blob: 75258b0fecf739865277ce88e5c3b2f09710bdfd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
(define (filter f strm)
(cond ((empty-stream? strm) nil)
((f (head strm)) (cons-stream (head strm) (filter f (tail strm))))
(else (filter f (tail strm))) ))
(define (accumulate f start strm)
(if (empty-stream? strm)
start
(f (head strm) (accumulate f start (tail strm))) ))
(define (range a b)
(if (> a b)
nil
(cons-stream a (range (1+ a) b)) ))
(define (perfect? n)
(= n (accumulate +
0
(filter (lambda (x) (= 0 (remainder n x)))
(range 1 (-1+ n)) ) )))
|