素数列生成
エラトステネスのふるい
haskellの例
https://stackoverflow.com/a/3596536
code:hs
primes :: Integer
primes = sieve 2..
where
sieve (p:xs) = p : sieve [x|x <- xs, x mod p > 0]
ここの最初に書いてるゴルフコードも同じだな
code:hs
-- 37打基本型
p=f2..;f(p:x)=p:fn|n<-x,mod n p>0
記事内では更に高速化してる
https://web.archive.org/web/20100710032905/http://en.literateprograms.org/Sieve_of_Eratosthenes_(Haskell)