From: Neil Smith Date: Tue, 13 Dec 2022 11:22:03 +0000 (+0200) Subject: Tidying X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=7c7d99a7943d4cc178672dcf3f049faf05f80b8f;p=advent-of-code-22.git Tidying --- diff --git a/advent10/Main.hs b/advent10/Main.hs index 764638f..4ac9abc 100644 --- a/advent10/Main.hs +++ b/advent10/Main.hs @@ -1,4 +1,4 @@ --- Writeup at https://work.njae.me.uk/2022/12/10/advent-of-code-2022-day-9/ +-- Writeup at https://work.njae.me.uk/2022/12/13/advent-of-code-2022-day-10/ import AoC import Data.Text (Text) @@ -23,23 +23,22 @@ main = putStrLn $ part2 regVals part1 :: [Signal] -> Int -part1 regVals = calculateSixSignals $ extractSignals regVals +part1 = calculateSixSignals . extractSignals part2 :: [Signal] -> String part2 regVals = unlines display - where pixels = map isLit regVals - rows = chunksOf 40 pixels - display = fmap (fmap showPixel) rows + where pixels = map (showPixel . isLit) regVals + display = chunksOf 40 pixels apply :: [Operation] -> [Signal] -apply ops = zip [1..] $ scanl' (+) 1 $ concatMap applyOp ops +apply = zip [1..] . scanl' (+) 1 . concatMap applyOp applyOp :: Operation -> [Int] -applyOp Noop = [0] +applyOp Noop = [0] applyOp (Addx d) = [0, d] extractSignals :: [Signal] -> [Signal] -extractSignals signals = filter (\(t, _n) -> (t + 20) `mod` 40 == 0) signals +extractSignals = filter (\(t, _n) -> (t + 20) `mod` 40 == 0) calculateSixSignals :: [Signal] -> Int calculateSixSignals signals = sum [ (t * n) @@ -47,13 +46,11 @@ calculateSixSignals signals = sum [ (t * n) , t <= 220 ] - isLit :: Signal -> Bool isLit (n, x) = abs (x - c) <= 1 where c = colummOf n colummOf :: Int -> Int --- colummOf n = (n - 1) `mod` 40 + 1 colummOf n = (n - 1) `mod` 40 showPixel :: Bool -> Char