AoC/2019/day8/day8.hs
2019-12-08 07:14:04 +01:00

18 lines
522 B
Haskell

{-# LANGUAGE LambdaCase #-}
import Data.List.Split
import Data.List
main = do
content <- chunksOf (25*6) <$> head <$> lines <$> readFile "input"
print (day8a content)
putStrLn (day8b content)
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]
day8b xs = intercalate "\n" $ map (map (\case '0'->' ';'1'->'•')) $ chunksOf 25 img
where img = map (head . filter (/='2')) $ transpose xs