1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

来年の素数日を列挙してみた

Last updated at Posted at 2012-03-16

コード:

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"

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?