You are here: Home Blog Comments Re:キミならどう書く 2.0 - ROUND 1 -

Personal tools

Re:キミならどう書く 2.0 - ROUND 1 -

Posted by Takumi Iino at 2006-06-23 02:04

gaucheの遅延ストリームでオーソドックスふるいをつかって。
長い。
(use util.stream)
(define ones (stream-cons 1 ones))
(define (add-streams s1 s2) (stream-map + s1 s2))
(define integer (stream-cons 1 (add-streams ones integer)))
(define prime-stream
(let loop ((primes (stream-cdr integer)))
(stream-cons (stream-car primes)
(loop
(stream-filter
(lambda (x)
(not (= (remainder x (stream-car primes)) 0)))
primes)))))
(let loop ((stream prime-stream))
(if (> 100 (stream-car stream))
(cons (stream-car stream) (loop (stream-cdr stream)))
'()))

Parent entry キミならどう書く 2.0 - ROUND 1 -