Created
November 6, 2012 00:06
-
-
Save TakashiNakagawa/4021281 to your computer and use it in GitHub Desktop.
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
;1.11 | |
;n < 3 f(n) = n, n >= 3 f(n) = f(n - 1) + 2f(n - 2) + 3f(n-3) | |
(define (func n) | |
(cond ((< n 3) n) | |
(else (+ (func (- n 1)) (* 2 (func (- n 2))) (* 3 (func (- n 3))))))) | |
(print (func 10)) | |
(define (func n) | |
(func-iter 2 1 0 n)) | |
(define (func-iter a3 a2 a1 count) | |
(cond ((= count 0) a1) | |
((= count 1) a2) | |
((= count 2) a3) | |
(else (func-iter (+ a3 (* 2 a2) (* 3 a1)) a3 a2 (- count 1))))) | |
(print (func 10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment