"血をもって書け。そうすればあなたは、血が精神だということを経験するだろう。"

2008-04-25から1日間の記事一覧

Problem17

1 から 5 までの数字を英単語で書けば one, two, three, four, five であり、全部で 3 + 3 + 4 + 4 + 5 = 19 の文字が使われている。では 1 から 1000 (one thousand) までの数字をすべて英単語で書けば、全部で何文字になるか。注: 空白文字やハイフンを数…

Problem13

以下の50桁の数字100個の総和の上位10桁を求めよ。(略) http://odz.sakura.ne.jp/projecteuler/index.php?Problem%2013 Haskell 数字は"p13num"に書いてあるとする。 IOモナドを使って main=readFile "p13num" >>= print . take 10 . show . sum . map (\x->…

Problem16

2^15 = 32768 であり、これの各数字の合計は 3 + 2 + 7 + 6 + 8 = 26 となる。同様にして、2^1000 の各数字の合計を求めよ。 Haskell main=print $ sumdigit $ 2^1000 sumdigit a |a<10 = a |otherwise = mod a 10 +(sumdigit $ div a 10) answer 1366