Skip to content

Instantly share code, notes, and snippets.

@zeptometer
Created November 29, 2013 13:56
Show Gist options
  • Select an option

  • Save zeptometer/7706035 to your computer and use it in GitHub Desktop.

Select an option

Save zeptometer/7706035 to your computer and use it in GitHub Desktop.
(define (fib2 n)
(let loop ((stack (list n)) (ans 0))
(if (null? stack)
ans
(let ((top (car stack)))
(cond ((= top 0) (loop (cdr stack) ans))
((= top 1) (loop (cdr stack) (+ ans 1)))
(else (loop `(,(- top 1) ,(- top 2) ,@(cdr stack)) ans)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment