From 1bb30457aa18d0076683954eb3e4c467c6c27cdb Mon Sep 17 00:00:00 2001 From: Gattix Date: Thu, 7 Dec 2023 14:04:36 +0100 Subject: [PATCH] gqG --- 2023/day07/day07.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/2023/day07/day07.hs b/2023/day07/day07.hs index 8042268..f11d595 100644 --- a/2023/day07/day07.hs +++ b/2023/day07/day07.hs @@ -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 @@ -27,7 +27,7 @@ handType (C x1 x2 x3 x4 x5) = where cList = sort $ map length $ group sList sList = sort [x1, x2, x3, x4, x5] - j = length (filter (==1) sList) + j = length (filter (== 1) sList) main :: IO () main = do @@ -35,17 +35,17 @@ main = do print $ day07 (parse False input) print $ day07 (parse True input) - day07 :: [(Hand, Int)] -> Int -day07 = sum . zipWith (*) [1..] . map snd . sort +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) - 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 - g x = error ("parseHand: Malformed input: " ++ show x) + 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 + g x = error ("parseHand: Malformed input: " ++ show x) digitToCard :: Bool -> Char -> Int digitToCard p2 x