16 lines
410 B
Haskell
16 lines
410 B
Haskell
|
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
|