2
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.

今年の素数日を計算してみる

Posted at

2012年の素数日は以前計算したのだが、今年2013年の素数日も計算してみる。
前のコード、コマンドライン第1引数を年と解釈して計算するように仕様を変えた。

primedays.hs
import Data.Time.Calendar
import System (getArgs)
isPrime n=not $ or $ map (\a->n `mod` a==0)
            $ takeWhile (\i->i*i<=n) [2..]
primeDays y=map (\a->filter (/= '-') $ show a) $ takeWhile (< fromGregorian (y+1) 1 1) 
      $ iterate (\d->addDays 1 d) $ fromGregorian y 1 1
main=do
  args<-getArgs
  case args of
    y:_ ->mapM_ (\a->putStrLn a) $ filter (isPrime.read) $ primeDays $ read y
    _ ->putStrLn "Usage: primedays <year>"

実行してみる

> ghc primedays
> primedays 2013
20130203
20130223
20130403
20130413
20130503
20130521
20130527
20130529
20130707
20130829
20131019
20131031
20131103
20131109
20131117
20131129
20131207
20131211
20131217
20131229

ということで、今日2/3の次は2/23のようです。
素数萌えの皆さん、参考まで。

2
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
2
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?