9 text <- readFile "data/advent08.txt"
10 let digits = successfulParse text
11 let layers = chunksOf (imageWidth * imageHeight) digits
13 putStrLn $ part2 layers
19 part1 layers = (count 1 target) * (count 2 target)
20 where target = minimumBy (comparing (count 0)) layers
22 part2 layers = unlines rows
23 where pixelLayers = transpose layers
24 pixels = map firstVisible pixelLayers
25 dPixels = map showPixel pixels
26 pixelRows = chunksOf imageWidth dPixels
27 rows = map concat pixelRows
30 firstVisible = head . dropWhile (== 2)
33 showPixel 1 = "\x2588"
36 count n = length . filter (== n)
38 -- Count the number of times a predicate is true
39 -- (Taken from GHC API utility functions)
41 -- count :: (a -> Bool) -> [a] -> Int
44 -- go !n (x:xs) | p x = go (n+1) xs
45 -- | otherwise = go n xs
48 successfulParse :: String -> [Int]
49 successfulParse input = map digitToInt input