Skip to content

Instantly share code, notes, and snippets.

@balinterdi
Created January 10, 2011 17:09
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 balinterdi/773068 to your computer and use it in GitHub Desktop.
Save balinterdi/773068 to your computer and use it in GitHub Desktop.
(defn fibo [n]
(cond
(= n 0) 0
(= n 1) 1
:else (+ (fibo (dec n)) (fibo (- n 2)))))
(defn fibo-toc [n]
(letfn [(fib
[current next n]
(if (zero? n)
current
(recur next (+ current next) (dec n))))]
(fib 0 1 n)))
(def n 50)
; (time (println (fibo n)))
(time (println (fibo-toc n)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment