sicp-ex-4.21



<< Previous exercise (4.20) | Index | Next exercise (4.22) >>


meteorgan

  
  
  
 ;; a 
  (lambda (n)  
    ((lambda (fib) 
       (fib fib n)) 
     (lambda (f n) 
       (cond ((= n 0) 0) 
             ((= n 1) 1) 
             (else (+ (f f (- n 2)) (f f (- n 1)))))))) 
  
 ;; b. filling the box as sequence: 
 ev? od? (- n 1) 
 ev? od? (- n 1) 

Rptx

  
  
  
 ;; a  
 ; this fib procedure uses the iterative version of fib. 
 ((lambda (n) 
    ((lambda (fib) 
       (fib fib 1 0 n)) 
     (lambda (fib a b count) 
       (if (= count 0) 
           b 
           (fib fib (+ a b) a (- count 1)))))) 
  10)