diff --git a/day02b/src/Main.hs b/day02b/src/Main.hs index 92aa8fc..b40f328 100644 --- a/day02b/src/Main.hs +++ b/day02b/src/Main.hs @@ -22,10 +22,13 @@ mapCubes :: T.Text -> (Integer, [[(Integer, String)]]) mapCubes line = parseParts $ T.splitOn (T.pack ": ") line mergeMaxCube :: [(Integer, String)] -> (Integer, String) -> [(Integer, String)] -mergeMaxCube acc (aa, col) = (\(a, c) -> if c == col then (max a aa, c) else (a, c)) <$> acc +mergeMaxCube (h@(ax, colx) : xs) b@(ab, col) + | colx == col = (max ax ab, colx) : xs + | otherwise = h : mergeMaxCube xs b +mergeMaxCube [] v = [v] main :: IO () main = do lns <- lines <$> getContents let values = mapCubes . T.pack <$> lns - print $ sum $ product . (fst <$>) . foldl mergeMaxCube [(0, "red"), (0, "green"), (0, "blue")] . concat . snd <$> values + print $ sum $ product . (fst <$>) . foldl mergeMaxCube [] . concat . snd <$> values