Skip to content

Instantly share code, notes, and snippets.

@diegoeche
Created October 16, 2009 04:40
Show Gist options
  • Save diegoeche/211563 to your computer and use it in GitHub Desktop.
Save diegoeche/211563 to your computer and use it in GitHub Desktop.
;; Exercise 1.19 of SICP
(define (fib n)
(fib-iter 1 0 0 1 n))
(define (fib-iter a b p q count)
(cond ((= count 0) b)
((even? count)
(fib-iter a
b
(+ p 1)
(+ p p 1)
(/ count 2)))
(else
(fib-iter (+ (* b q) (* a q) (* a p))
(+ (* b p) (* a q))
p
q
(- count 1)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment