AoC/2019/day8/day8.hs
2019-12-08 08:29:36 +01:00

19 lines
521 B
Haskell

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