--- 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)
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)
, 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