Skip to content

Instantly share code, notes, and snippets.

@timmc
Created October 9, 2012 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timmc/3862052 to your computer and use it in GitHub Desktop.
Save timmc/3862052 to your computer and use it in GitHub Desktop.
(defn fibseq
([]
(cons 0 (cons 1 (fibseq 0 1))))
([n0 n1]
(let [n2 (+' n0 n1)] ;; using auto-promoting addition
(cons n2 (lazy-seq (fibseq n1 n2))))))
(reduce + (filter even? (take-while #(<= % 4e6) (fibseq))))
;; user=> (nth (fibseq) 500)
;; 139423224561697880139724382870407283950070256587697307264108962948325571622863290691557658876222521294125N
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment