From 6151efafa2e962bbe9cd25e5b9d6f1145836aea3 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Mon, 9 Dec 2019 09:20:55 +0000 Subject: [PATCH] A little tidying --- advent08/src/advent08.hs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/advent08/src/advent08.hs b/advent08/src/advent08.hs index fe00af5..7c02922 100644 --- a/advent08/src/advent08.hs +++ b/advent08/src/advent08.hs @@ -2,7 +2,6 @@ import Data.List import Data.List.Split import Data.Char import Data.Ord -import Data.Function main :: IO () main = do @@ -12,7 +11,6 @@ main = do print $ part1 layers putStrLn $ part2 layers - imageWidth = 25 imageHeight = 6 @@ -22,28 +20,15 @@ part1 layers = (count 1 target) * (count 2 target) part2 layers = unlines rows where pixelLayers = transpose layers pixels = map firstVisible pixelLayers - dPixels = map showPixel pixels - pixelRows = chunksOf imageWidth dPixels - rows = map concat pixelRows - + image = concatMap showPixel pixels + rows = chunksOf imageWidth image firstVisible = head . dropWhile (== 2) showPixel 0 = " " showPixel 1 = "\x2588" - count n = length . filter (== n) --- Count the number of times a predicate is true --- (Taken from GHC API utility functions) - --- count :: (a -> Bool) -> [a] -> Int --- count p = go 0 --- where go !n [] = n --- go !n (x:xs) | p x = go (n+1) xs --- | otherwise = go n xs - - successfulParse :: String -> [Int] successfulParse input = map digitToInt input \ No newline at end of file -- 2.34.1