Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created October 1, 2010 11:24
Show Gist options
  • Save oskimura/606074 to your computer and use it in GitHub Desktop.
Save oskimura/606074 to your computer and use it in GitHub Desktop.
module Euler20 where
import Data.Maybe (fromMaybe)
-- 文字(0-9)を数字に
charToInteger :: Char -> Maybe Integer
charToInteger = flip lookup (zip ['0'..'9'] [0..9])
-- 文字列(0-9)*を数字に
strToInt :: String -> [Integer]
strToInt = map (fromMaybe 0 . charToInteger)
euler20 = sum . toDidits $ 100
where
toDidits = strToInt . text
text = show . fact
fact n = product [1..n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment