ext_194162 (
gemini6ice.livejournal.com
) wrote
in
dougo
2008-03-17 01:24 pm (UTC)
no subject
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))
(
14 comments
)
Post a comment in response:
From:
Anonymous
This account has disabled anonymous posting.
OpenID
Identity URL:
Log in?
Dreamwidth account
Account name
Password
Log in?
If you don't have an account you can
create one now
.
Subject
HTML doesn't work in the subject.
Formatting type
Casual HTML
Markdown
Raw HTML
Rich Text Editor
Message
[
Home
|
Post Entry
|
Log in
|
Search
|
Browse Options
|
Site Map
]
no subject
;)
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))