From 261bfbaa66c0293585c0d8f7ccb6fe4423bcad4e Mon Sep 17 00:00:00 2001 From: tzlil Date: Sat, 2 Dec 2023 19:25:43 +0200 Subject: lol --- 2/1.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to '2/1.hs') diff --git a/2/1.hs b/2/1.hs index 4f3a5ae..1073b72 100644 --- a/2/1.hs +++ b/2/1.hs @@ -12,18 +12,18 @@ type Handful = (Color, Int) type Set = M.Map Color Int type Game = (Int, [Set]) -red = try $ string "red" *> pure Red -green = try $ string "green" *> pure Green -blue = try $ string "blue" *> pure Blue +red = string "red" *> pure Red +green = string "green" *> pure Green +blue = string "blue" *> pure Blue color :: Parser Color color = red <|> green <|> blue handful :: Parser Handful -handful = space *> (flip (,) <$> read <$> many1 digit) <* space <*> color +handful = liftM2 (flip (,)) (space *> (read <$> many1 digit)) (space *> color) set = M.fromList <$> (sepBy handful $ string ",") -game = string "Game " *> ((,) <$> read <$> many1 digit) <* string ":" <*> sepBy set (string ";") +game = liftM2 (,) (string "Game " *> (read <$> many1 digit)) (string ":" *> sepBy set (string ";")) games = sepBy game newline -- cgit 1.4.1