Files
advent-of-code-2023/day13/Part2.hs
2023-12-13 14:29:31 +01:00

21 lines
971 B
Haskell

module Part2 where
import Commons
import Data.Array (bounds, (!), (//))
findSmudges :: (Int, Int) -> [Int] -> [Pattern] -> [Int]
findSmudges _ [] [] = []
findSmudges (y, x) (sh: st) (ph: pt)
| x > snd (snd $ bounds ph) = findSmudges (y + 1, 1) (sh: st) (ph: pt)
| otherwise = let iV = if sh < 100 then sh else 0
iH = if sh >= 100 then sh `div` 100 else 0
newT = if ph ! (y, x) == Ash then Rock else Ash
newR = getVerticalReflection 1 iV (ph // [((y, x), newT)])
+ 100 * getHorizontalReflection 1 iH (ph // [((y, x), newT)])
in if newR > 0 then newR: findSmudges (1, 1) st pt
else findSmudges (y, x + 1) (sh: st) (ph: pt)
getSummaryWithSmudges :: [Int] -> [Pattern] -> [Int]
getSummaryWithSmudges = findSmudges (1, 1)