Browse files

tamir's version

  • Loading branch information...
1 parent 6121b72 commit 7ab01d25301ffccc2eaf0c87661dbebc310c0091 @jrheard committed Jun 17, 2011
Showing with 8 additions and 0 deletions.
  1. +8 −0 two.lisp
View
8 two.lisp
@@ -11,6 +11,14 @@
(f (1+ idx) t2 (+ t1 t2)))))
(f 1 0 1)))
+; tamir's version - way more elegant, but doesn't seem to optimize out
+(defun tfib (index)
+ (labels ((f (idx acc)
+ (cond ((eq idx 0) acc)
+ ((eq idx 1) (1+ acc))
+ (t (f (- idx 1) (f (- idx 2) acc))))))
+ (f index 0)))
+
(princ
(loop for i from 1
for term = (fib i)

0 comments on commit 7ab01d2

Please sign in to comment.