This commit is contained in:
2023-12-13 14:26:33 +01:00
parent 2f36550ebe
commit 03c18bbe91
5 changed files with 116 additions and 0 deletions

20
day13/Part2.hs Normal file
View File

@@ -0,0 +1,20 @@
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)