module Main where import Data.List import Data.Ord import Input blockBy :: Int -> [a] -> [[a]] blockBy _ [] = [] blockBy n l = uncurry (:) (fmap (blockBy n) (splitAt n l)) main :: IO () main = do layers <- blockBy (25 * 6) . head <$> getInput 8 let count x = length . filter (== x) layer = minimumBy (comparing (count '0')) layers print (count '1' layer * count '2' layer) let combine = zipWith (\a b -> if a == '2' then b else a) image = foldl1 combine layers image' = map (\c -> if c == '1' then '#' else '.') image mapM_ putStrLn (blockBy 25 image')