Skip to content

Instantly share code, notes, and snippets.

@kkolotyuk
Created March 26, 2014 06:40
Show Gist options
  • Select an option

  • Save kkolotyuk/9777871 to your computer and use it in GitHub Desktop.

Select an option

Save kkolotyuk/9777871 to your computer and use it in GitHub Desktop.
(defn tail-fibo [n]
(letfn [(fib [current next n]
(if (zero? n)
current
(fib next (+ current next) (dec n))))]
(fib 0N 1N n)))
(tail-fibo 1000000) ;; stackoverflow
(defn recur-fibo [n]
(letfn [(fib [current next n]
(if (zero? n)
current
(recur next (+ current next) (dec n))))]
(fib 0N 1N n)))
(recur-fibo 1000000) ;; works!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment