Improved project structure.
This commit is contained in:
15
haskell/e022.hs
Normal file
15
haskell/e022.hs
Normal file
@@ -0,0 +1,15 @@
|
||||
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
|
||||
Reference in New Issue
Block a user