From cd31a8035a378cf58242444f9068f7d441ff42a7 Mon Sep 17 00:00:00 2001 From: tzlil Date: Sat, 2 Dec 2023 19:35:02 +0200 Subject: make pointfree again --- 2/2.hs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to '2/2.hs') diff --git a/2/2.hs b/2/2.hs index 3d26a35..ba01542 100644 --- a/2/2.hs +++ b/2/2.hs @@ -8,7 +8,6 @@ import qualified Data.Map as M import Control.Monad data Color = Red | Green | Blue deriving (Show,Eq,Ord) -type Handful = (Color, Int) type Set = M.Map Color Int type Game = (Int, [Set]) @@ -16,10 +15,8 @@ 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 = liftM2 (flip (,)) (space *> (read <$> many1 digit)) (space *> color) set = M.fromList <$> (sepBy handful $ string ",") @@ -30,6 +27,4 @@ games = sepBy game newline solution :: Game -> Int solution = product . M.elems . M.unionsWith max . snd -main = head <$> getArgs >>= \a -> do - r <- readFile a - print $ sum $ map solution $ either (error.show) id $ parse games a r \ No newline at end of file +main = liftM2 (>>=) readFile (((print . sum . map solution . either (error.show) id) .) . parse games) =<< head <$> getArgs \ No newline at end of file -- cgit 1.4.1