Files
advent-of-code-2023/day16/Part2.hs
2023-12-16 16:06:19 +01:00

19 lines
770 B
Haskell

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)