ProjectEular

-- Problem 8

module Main (main) where

import qualified List (tails)
import qualified Char (digitToInt)

main :: IO ()
main = do
    digits_str <- getContents
    print $ problem8 $ to_digits digits_str

problem8 :: [Int] -> Int
problem8 = maximum . map product . lists_5digits

-- [[7,3,1,6,7], [3,1,6,7,1], [1,6,7,1,7], ..., [6,3,4,5,0]]
lists_5digits :: [Int] -> [[Int]]
lists_5digits = filter (\xs -> length xs == 5) . map (take 5) . List.tails

to_digits :: String -> [Int]
to_digits = map Char.digitToInt . concat . lines

トップ   差分 バックアップ リロード   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS