Skip to content

Instantly share code, notes, and snippets.

@loganlinn
Created August 16, 2011 21:01
Show Gist options
  • Save loganlinn/1150166 to your computer and use it in GitHub Desktop.
Save loganlinn/1150166 to your computer and use it in GitHub Desktop.
Exercise 1.1 from SICP
; f(n) = n, n < 3
; = f(n-1) + 2f(n-2) + 3f(n-3), n >= 3
(define (f-iter n)
(fp 2 1 0 n 3))
(define (fp a b c n i)
(if (= n i)
(+ a (* 2 b) (* 3 c))
(fp (+ a (* 2 b) (* 3 c))
a
b
n
(+ i 1))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment