This commit is contained in:
Gattix 2023-12-07 14:04:36 +01:00
parent 4bbed10f38
commit 1bb30457aa

View File

@ -1,6 +1,6 @@
import Data.Char
import Data.Function (on)
import Data.List
import Data.Char
data Hand =
C Int Int Int Int Int
@ -35,13 +35,13 @@ main = do
print $ day07 (parse False input)
print $ day07 (parse True input)
day07 :: [(Hand, Int)] -> Int
day07 = sum . zipWith (*) [1 ..] . map snd . sort
parse :: Bool -> String -> [(Hand, Int)]
parse p2 = map (f . words) . lines
where f [x,y] = (parseHand x, read y)
where
f [x, y] = (parseHand x, read y)
f x = error ("parse: Malformed input: " ++ show x)
parseHand = g . map (digitToCard p2)
g [x1, x2, x3, x4, x5] = C x1 x2 x3 x4 x5