Created
November 4, 2012 18:55
-
-
Save enigmaticape/4013070 to your computer and use it in GitHub Desktop.
Iterative (tail recursive) Fibonacci in Scheme (a snippet from SICP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/)