scheme-playground/sicp-exercises/exercise1-11.scm
2024-09-26 21:29:47 +02:00

18 lines
409 B
Scheme

(define (fn-recursive n)
(cond ((< n 3) n)
(else (+ (fn-recursive (- n 1)) (* 2 (fn-recursive (- n 2))) (* 3 (fn-recursive (- n 3)))))))
(define (fn-wrapper n)
(define (fn-iterative n1 n2 n3 count)
(cond ((= count 0) n1)
(else (fn-iterative (+ n1 (* 2 n2) (* 3 n3)) n1 n2 (- count 1) ))))
(if (< n 3)
n
(fn-iterative 2 1 0 (- n 2)))
)
(print (fn-recursive 10))
(print (fn-wrapper 10))