Last active
August 29, 2015 14:03
-
-
Save arademaker/c1ba0f881527ed70d6d7 to your computer and use it in GitHub Desktop.
Fibonacci functions in CL. Used in the presentation of Chapter 0 of http://books.google.com/books?id=3sCxQgAACAAJ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun fib1 (n) | |
(cond | |
((equal n 0) 0) | |
((equal n 1) 1) | |
(t (+ (fib1 (- n 1)) | |
(fib1 (- n 2)))))) | |
(defun fib2 (n) | |
(labels ((calc-fib (n a b) | |
(if (= n 0) | |
a | |
(calc-fib (- n 1) b (+ a b))))) | |
(calc-fib n 0 1))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment