From d7e41f1e93eac045329b6ea91ae150d517e443a3 Mon Sep 17 00:00:00 2001 From: tzlil Date: Sat, 2 Dec 2023 14:09:07 +0200 Subject: a little nicer --- 2/2.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to '2/2.hs') diff --git a/2/2.hs b/2/2.hs index 0d1f855..ed96a26 100644 --- a/2/2.hs +++ b/2/2.hs @@ -25,7 +25,9 @@ handful = space *> (flip (,) <$> read <$> many1 digit) <* space <*> color set = M.fromList <$> (sepBy handful $ string ",") game = string "Game " *> ((,) <$> read <$> many1 digit) <* string ":" <*> sepBy set (string ";") +games = sepBy game newline + solution :: Game -> Int solution = product . M.elems . M.unionsWith max . snd -main = head <$> getArgs >>= readFile >>= print . sum . map solution . catMaybes . map (either (const Nothing) Just . parse game "") <$> lines \ No newline at end of file +main = head <$> getArgs >>= readFile >>= print . sum . map solution . either (error.show) id . parse games "" \ No newline at end of file -- cgit 1.4.1