Created
March 23, 2020 04:16
-
-
Save inopinatus/0ad30ed1a65193c034e8ed0c0e92548e to your computer and use it in GitHub Desktop.
yfib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
y = ->(f) { | |
->(x) { x.(x) }.( | |
->(x) { f.(->(v) { x.(x).(v) }) } ) | |
} | |
fib = y.(->(f) { | |
->(n) { n < 2 ? Array(0..n) : f[n-1].then { _1 << _1[-1] + _1[-2] } } | |
}) | |
fib[6] #=> [0, 1, 1, 2, 3, 5, 8] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment