15 lines
521 B
Haskell
15 lines
521 B
Haskell
|
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
|