Created
October 31, 2010 17:47
-
-
Save mattyw/656896 to your computer and use it in GitHub Desktop.
An example from Bruce Tate's 7 languages in 7 weeks, Fib numbers in clojure. Try running this with (nth-fib 500). Very fast
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-pair [[a b]] [b (+ a b)]) | |
(defn nth-fib [n] | |
"Return the nth fib number" | |
(nth (map first (iterate fib-pair [0 1])) n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment