コード:
primes2012.hs
import Data.Time.Calendar
isPrime n=not $ or $ map (\a->n `mod` a==0)
$ takeWhile (\i->i*i<=n) [2..]
days=map (\a->filter (/= '-') $ show a) $ takeWhile (< fromGregorian 2013 1 1)
$ iterate (\d->addDays 1 d) $ fromGregorian 2012 1 1
main=mapM_ (\a->print a) $ filter (isPrime.read) days
結果:
"20120203"
"20120207"
"20120213"
"20120323"
"20120407"
"20120501"
"20120509"
"20120531"
"20120623"
"20120629"
"20120713"
"20120717"
"20120719"
"20120729"
"20120801"
"20120819"
"20120827"
"20120923"
"20120927"
"20121103"
"20121107"
"20121121"