diff --git a/2019/day8/day8.hs b/2019/day8/day8.hs index f317ad8..43d3d8b 100644 --- a/2019/day8/day8.hs +++ b/2019/day8/day8.hs @@ -1,6 +1,7 @@ {-# LANGUAGE LambdaCase #-} import Data.List.Split import Data.List +import Data.Ord main = do content <- chunksOf (25*6) <$> head <$> lines <$> readFile "input" @@ -11,7 +12,7 @@ count x = (length . filter (==x)) day8a xs = let l = toLayers xs in (count '2' l) * (count '1' l) - where toLayers xs = snd $ minimum [(count '0' x, x) | x <- xs] + where toLayers xs = minimumBy (comparing (count '0')) xs -day8b xs = intercalate "\n" $ map (map (\case '0'->' ';'1'->'•')) $ chunksOf 25 img +day8b xs = unlines $ map (map (\case '0'->' ';'1'->'•')) $ chunksOf 25 img where img = map (head . filter (/='2')) $ transpose xs