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
@lmarinho - I'd been playing there all morning actually. Thanks for the rec though!
@fogus - Totally agreed. As you covered in your book (which I'm loving), there's something beautifully declarative about saying "this is how you calculate ALL fibs", and then just taking what you need.