Created
January 28, 2013 18:50
-
-
Save r00k/4658025 to your computer and use it in GitHub Desktop.
Kinda mind-blowing fibonacci-sequence-producing function.
This file contains hidden or 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
(defn fib [n] | |
(take n (map first (iterate (fn [[a b]] [b (+ a b)]) [1 1])))) | |
(fib 5) => (1 1 2 3 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do something similar in JS though it's not as pretty:
Wouldn't be hard to write some library functions like take() to get the nth element etc.