euler/haskell/e022.hs

16 lines
410 B
Haskell
Raw Normal View History

2015-01-04 23:52:50 +01:00
import Data.List
toScore :: Char -> Integer
toScore b = snd . head . dropWhile (\(c, i) -> c /= b) $ zip ['A'..'Z'] [1..26]
nameScore :: (Integer, String) -> Integer
nameScore (i, s) = i * (sum (map toScore s))
listScore :: [String] -> Integer
listScore = sum . map nameScore . zip [1..]
main = do
file <- readFile "22.txt"
let names = sort . read $ file :: [String]
putStrLn . show . listScore $ names