Created
October 1, 2010 11:24
-
-
Save oskimura/606074 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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