Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Iterative function f(n) from SICP exercise 1.11
; f(n) = n if n < 3,
; f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n > 3
;
; iterative (via tail recursion optimisation)
(define (F-iter a b c count)
(if (= count 0)
c
(F-iter (+ a (* 2 b) (* 3 c))
a
b
(- count 1) ) ))
(define (F n)
(if (< n 3)
n
(F-iter 2 1 0 n)))
@enigmaticape

This comment has been minimized.

Copy link
Owner Author

enigmaticape commented Nov 16, 2012

From a discussion of the solution to SICP exercise 1.11 at http://www.enigmaticape.com/blog/sicp-exercise-1-11-iterative-function-fn/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.