You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
556 B
18 lines
556 B
(define (square x) |
|
(* x x)) |
|
|
|
(define (fib n) |
|
(define (fib-iter a b p q count) |
|
(cond ((= count 0) b) |
|
((even? count) |
|
(fib-iter a |
|
b |
|
(+ (square p) (square q)) ; compute p' |
|
(+ (* 2 p q) (square q)) ; compute q' |
|
(/ count 2))) |
|
(else (fib-iter (+ (* b q) (* a q) (* a p)) |
|
(+ (* b p) (* a q)) |
|
p |
|
q |
|
(- count 1))))) |
|
(fib-iter 1 0 0 1 n))
|
|
|