3 ms·
If I absolutely had to write a recursive solution, something like this (should have all recursive calls in a tail position, may require trading debugability for
by randomswede 5y ago
If I absolutely had to write a recursive solution, something like this (should have all recursive calls in a tail position, may require trading debugability for speed):
(defun tail-fib (n &optional (v0 0) (v1 1)
(cond ((zerop n) v0)
(t (tail-fib (1- n) v1 (+ v0 v1)))))
- jonsen 5y agoI don’t know much Lisp. Is that why I, except for syntax, see no difference from emptybits’s nth-fibonacci?