Skip to content

Instantly share code, notes, and snippets.

@lenst
Created March 28, 2009 11:20
Show Gist options
  • Save lenst/87088 to your computer and use it in GitHub Desktop.
Save lenst/87088 to your computer and use it in GitHub Desktop.
;; My take on Fibonacci numbers
(defn gen-fibo []
(let [fibo (atom nil)]
(reset! fibo (lazy-cat [0 1] (lazy-seq (map + @fibo (rest @fibo)))))))
(def fib (proxy [clojure.lang.Seqable] []
(seq [] (gen-fibo))))
user> (take 10 fib)
(0 1 1 2 3 5 8 13 21 34)
user> (nth (seq fib) 10000)
336447648764..59947366875 ; 2067 digits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment