Refactor day 16

This commit is contained in:
2023-12-16 15:56:38 +01:00
parent 322b2b50c0
commit e772a7617c
3 changed files with 62 additions and 45 deletions

View File

@@ -9,10 +9,10 @@ getEnergized :: (Int, Int, Direction) -> Cavern -> [(Int, Int)]
getEnergized (y0, x0, d) = toList . delete (y0, x0) . Data.Set.map (\ (y, x, _) -> (y, x)) . lightBeam (y0, x0) d empty
getStarts :: Cavern -> [(Int, Int, Direction)]
getStarts c = [(y, 0, East) | y <- [1..(fst (snd $ bounds c))]]
++ [(y, 1 + snd (snd $ bounds c), West) | y <- [1..(fst (snd $ bounds c))]]
++ [(0, x, South) | x <- [1..(snd (snd $ bounds c))]]
++ [(1 + fst (snd $ bounds c), x, North) | x <- [1..(snd (snd $ bounds c))]]
getStarts c = [(y, 0, East) | y <- [1..fst (snd $ bounds c)]]
++ [(y, 1 + snd (snd $ bounds c), West) | y <- [1..fst (snd $ bounds c)]]
++ [(0, x, South) | x <- [1..snd (snd $ bounds c)]]
++ [(1 + fst (snd $ bounds c), x, North) | x <- [1..snd (snd $ bounds c)]]
getMaxEnergized :: Cavern -> Int
getMaxEnergized c = maximum (Prelude.map (\s -> length $ getEnergized s c) $ getStarts c)
getMaxEnergized c = maximum $ Prelude.map (\s -> length $ getEnergized s c) $ getStarts c