Skip to content

Instantly share code, notes, and snippets.

@enigmaticape
Created November 4, 2012 18:55
Show Gist options
  • Save enigmaticape/4013070 to your computer and use it in GitHub Desktop.
Save enigmaticape/4013070 to your computer and use it in GitHub Desktop.
Iterative (tail recursive) Fibonacci in Scheme (a snippet from SICP)
(define (fib n)
(fib-iter 1 0 n))
(define (fib-iter a b count)
(if (= count 0)
b
(fib-iter (+ a b) a (- count 1))))
@enigmaticape
Copy link
Author

Fibonacci function as given in SICP, used in discussion of solution to exercises 1.11 (http://www.enigmaticape.com/blog/sicp-exercise-1-11-iterative-function-fn/) and 1.13 (http://www.enigmaticape.com/blog/sicp-exercise-1-13/)

@tobisor
Copy link

tobisor commented Apr 3, 2017

HOLY M... thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment