Last active
August 29, 2015 14:03
-
-
Save Gallefray/98d07dfeadbf1bfe8966 to your computer and use it in GitHub Desktop.
Better fibonacci
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
(setq fibonacci-list `(0 1 1 2 3 5 8 13 21 34 55)) | |
(defun compute-fibonacci (n) | |
(let ((x (+ (get-fibonacci (- n 1)) | |
(get-fibonacci (- n 2))))) | |
(prog2 | |
(setq fibonacci-list (append fibonacci-list (list x))) | |
x))) | |
(defun get-fibonacci (n) | |
(if (<= n (list-length fibonacci-list)) | |
(nth (- n 1) fibonacci-list) | |
(compute-fibonacci n))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment