In [1]:
inputLine = head . lines <$> readFile "input/day08.txt"
In [2]:
imageSize = 25 * 6
In [3]:
import Data.List.Split
layers = chunksOf imageSize <$> inputLine
In [4]:
count digit = length . filter (==digit)
In [5]:
count012 layer = map (($ layer). count) ['0'..'2']
In [6]:
product12 [_, n1, n2] = n1 * n2
In [7]:
product12 . minimum . map count012 <$> layers
In [8]:
mergeLayers :: String -> String -> String
mergeLayers = zipWith (\ a b -> if a == '2' then b else a)
In [9]:
solution = foldl1 mergeLayers
In [10]:
solution . chunksOf 4 $ "0222112222120000"
In [11]:
pixel :: Char -> Char
pixel '0' = ' '
pixel '1' = '#'
In [12]:
import Data.List (intercalate)
(intercalate "\n" . chunksOf 25 . map pixel . solution <$> layers) >>= putStrLn