Skip to content

Instantly share code, notes, and snippets.

@Gallefray
Last active August 29, 2015 14:03
Show Gist options
  • Save Gallefray/98d07dfeadbf1bfe8966 to your computer and use it in GitHub Desktop.
Save Gallefray/98d07dfeadbf1bfe8966 to your computer and use it in GitHub Desktop.
Better fibonacci
(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