ext_194162 ([identity profile] gemini6ice.livejournal.com) wrote in [personal profile] dougo 2008-03-17 01:24 pm (UTC)

just to be difficult, 1 = 5 + (2i)^2

;)

Another solution would be to simply change prime? to composite? and reverse your true and false statements:

(define primes
(stream-cons
2
(stream-filter not(composite? (integers-starting-from 3)))))

(define (composite? n)
(define (iter ps)
(cond ((> (square (stream-car ps)) n) false)
((divisible? n (stream-car ps)) true)
(else (iter (stream-cdr ps)))))
(iter primes))

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting