Wednesday, June 3, 2009

Ex-1.33

(define (filtered-accumulate filter combiner
null-value term a next b)
(cond ((> a b) null-value)
((filter a)
(combiner (term a)
(filtered-accumulate filter combiner
null-value term
(next a) next b)))
(else
(filtered-accumulate filter combiner null-value
term (next a) next b))))
;a
(define (incf i) (+ i 1))
(define (sum-sq-prime-nums a b)
(filtered-accumulate prime? + 0 square a incf b))

;b
(define (return-arg arg) arg)
(define (prod-nums-lt-n n)
(define (relative-prime? x)
(if (> (gcd x n) 1) #f #t))
(filtered-accumulate relative-prime? * 1
return-arg 1 incf n))

No comments:

Post a Comment