Skip to content

Instantly share code, notes, and snippets.

@pingles
Created October 19, 2010 18:29
Show Gist options
  • Save pingles/634755 to your computer and use it in GitHub Desktop.
Save pingles/634755 to your computer and use it in GitHub Desktop.
;; tree-recursive fibonacci
(defn fib-recur
[n]
(cond (= n 0) 0
(= n 1) 1
:else (+ (fib-recur (- n 1))
(fib-recur (- n 2)))))
;;linear iteration fibonacci
(defn fib-iter
([n]
(fib-iter 1 0 n))
([a b count]
(if (= count 0)
b
(recur (+ a b)
a
(- count 1)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment