@@ 65,20 65,29 @@ step g (p@(x,y),d) = filter (\(p, _) -> Grid.inBounds g p) $
(Just SplitterEW, East) -> [((x+1,y), d)]
(Just SplitterEW, West) -> [((x-1,y), d)]
-partA :: Parse -> Int
-partA g = Set.size $ Set.map fst $ f Set.empty [((1,1), East)]
+energizedTiles :: Grid Thing -> Beam -> Int
+energizedTiles g = Set.size . Set.map fst . f Set.empty . flip (:) []
where f vs [] = vs
f vs (b:bs) =
let bs' = filter (\b' -> b' `Set.notMember` vs) $ step g b in
let vs' = Set.insert b vs in
f vs' (bs'++bs)
---partB :: Parse -> Parse
---partB = id
+partA :: Parse -> Int
+partA g = energizedTiles g ((1,1), East)
+
+partB :: Parse -> Int
+partB g =
+ let ((minX, minY), (maxX, maxY)) = Grid.bounds g in
+ maximum $ fmap (energizedTiles g) $
+ [((minX, y), East) | y <- [minY..maxY]]
+ ++ [((maxX, y), West) | y <- [minY..maxY]]
+ ++ [((x, minY), South) | x <- [minX..maxX]]
+ ++ [((x, maxY), North) | x <- [minX..maxX]]
main :: IO ()
main = with parser $ do
run' "16.example" "a example" partA 46
run' "16.input" "a input" partA 7210
- --run "16.example" "b example" partB
- --run "16.input" "b input" partB
+ run' "16.example" "b example" partB 51
+ run' "16.input" "b input" partB 7673