Advent of Code 2024 - Day 6Guard Gallivant
| Problem statement | Source code | Tags: Grid walkingBrute force
This problem pays tribute to 2018 day 5 (unimplemented).
Part 1
We can start by marking all cells that the guard will walk through, just by following the instructions. Each time, the guard either takes a step forward in the current direction, or turns right if it will be moving into an obstruction, exiting when it moves out of bounds.
Then for part 1, just count the number of cells marked with X in the matrix.
Part 2
Given the matrix from part 1, for each cell marked with X, we can check if adding an obstruction there would create a loop. I bet there are smart ways to detect loops, but I just simulate the walk again and see if I re-enter the same cell in the same direction.