Advent of Code 2024 (Day 4)
Published on: Sunday, December 1, 2024 at 8:15 PM PST
Written by Josh Bright
Intro
For day 4’s puzzle, we can think of it a bit like one of those word searches where you are given a grid of letters and the words can be in any direction. I thought this one was pretty fun, and my past experience with A* Pathfinding and Pygame RPG’s helped a bit here to explore surrounding squares.
Part 1
For part 1, we need to find a string going in any direction, even backwards. Looping over each letter in the grid, checking if it is the first letter, and then checking each direction (forwards and backwards) did the trick here. When doing these grid searches, I always find making sure that all your checks are valid is helpful to avoid index errors, when you try to check a letter outside of the grid.
Part 2
For part 2, we need to find MAS
but in an X shape. Did sort of the same thing here, where we go letter by letter in the grid, and when we find an S or M,
we check if its in a valid configuration making up the X shape. Finished this one pretty quickly, but enjoyed both of these puzzles greatly!