AoC/2019/day8/day8.hs

19 lines
523 B
Haskell
Raw Normal View History

2019-12-08 07:14:04 +01:00
{-# LANGUAGE LambdaCase #-}
2019-12-08 07:03:28 +01:00
import Data.List.Split
import Data.List
import Data.Ord
2019-12-08 07:03:28 +01:00
main = do
content <- chunksOf (25*6) <$> head <$> lines <$> readFile "input"
print (day8a content)
putStrLn (day8b content)
2019-12-08 07:14:04 +01:00
count x = (length . filter (==x))
2019-12-08 07:03:28 +01:00
day8a xs = let l = toLayers xs in
2019-12-08 07:14:04 +01:00
(count '2' l) * (count '1' l)
where toLayers xs = minimumBy (comparing (count '0')) xs
2019-12-08 07:03:28 +01:00
day8b xs = unlines $ map (map (\case '0'->' ';'1'->'•')) $ chunksOf 25 img
2019-12-08 07:14:04 +01:00
where img = map (head . filter (/='2')) $ transpose xs