(define (fib n)
(fib-iter 1 0 n))
(define (fib-iter a b count)
(if (= count 0)
b
(fib-iter (+ a b) a (- count 1))))
(define (fib< n)
(fib<-iter n 1 empty))
(define (fib<-iter n count l)
(cond ((> n (fib count)) (fib<-iter n (+ count 1) (cons (fib count) l)))
(else l)))
(define (euler2 n)
(euler2-iter (fib< n) 0))
(define (euler2-iter l sum)
(cond ((not (empty? l))
(cond ((even? (car l)) (euler2-iter (cdr l) (+ (car l) sum)))
(else (euler2-iter (cdr l) sum))))
(else sum)))
then I call the function by (euler2 4000000)
No comments:
Post a Comment