This commit is contained in:
2023-12-16 14:48:42 +01:00
parent 8e54e42899
commit 322b2b50c0
5 changed files with 112 additions and 16 deletions

18
day16/Part2.hs Normal file
View File

@@ -0,0 +1,18 @@
module Part2 where
import Commons
import Data.Set (empty, map, toList, delete)
import Data.Array (bounds)
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))]]
getMaxEnergized :: Cavern -> Int
getMaxEnergized c = maximum (Prelude.map (\s -> length $ getEnergized s c) $ getStarts c)