Day 16
This commit is contained in:
18
day16/Part2.hs
Normal file
18
day16/Part2.hs
Normal 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)
|
||||
Reference in New Issue
Block a user