Skip to content

Instantly share code, notes, and snippets.

@tsu-nera
Last active May 25, 2017 16:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsu-nera/06ed13f14b3337e14275 to your computer and use it in GitHub Desktop.
Save tsu-nera/06ed13f14b3337e14275 to your computer and use it in GitHub Desktop.
fibonacci with elisp
(defun fib (n)
(fib-iter 1 0 n))
(defun fib-iter (a b count)
(if (= count 0)
b
(fib-iter (+ a b) a (- count 1))))
(defun fib (n)
(cond ((= n 0) 0)
((= n 1) 1)
(t (+ (fib (- n 1))
(fib (- n 2))))))
(fib 4) ; => 3
(fib 5) ; => 5
(fib 6) ; => 8
(fib 7) ; => 13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment