AoC/2019/day8/day8.hs

15 lines
521 B
Haskell
Raw Normal View History

2019-12-08 07:03:28 +01:00
import Data.List.Split
import Data.List
main = do
content <- chunksOf (25*6) <$> head <$> lines <$> readFile "input"
print (day8a content)
putStrLn (day8b content)
toLayers xs = snd $ minimum [((length . filter (=='0')) x, x) | x <- xs]
day8a xs = let l = toLayers xs in
(length $ filter (=='2') l) * (length $ filter (=='1') l)
day8b xs = intercalate "\n" $ map (map (\x->if x=='0' then ' ' else '•')) $ chunksOf 25 img
where img = map (foldr (\x y->if x=='2' then y else x) '2') $ transpose xs