Part 1: Advent of Code 2024 Day 4 involves finding 'X' in a grid and walking three steps in eight directions from each 'X' creating a word. Solution involves cataloguing the coordinates of each 'X',checking each direction for the spelling of 'XMAS'.
Part 2: Advent of Code 2024 Day 4 involves finding 'M' in a grid and looking the configuration of a 5-cell phrase, MSSM, MMSS, SMMS, or SSMM, diagonally adjacent to 'A'. Solution involves finding every 'A', setting Stringified coordinates for each match and checking the four cells.
The JavaScript coding of the strategy covered the padding of the grid with a 3-cell thick border, all eight relative coordinates, as well as the algorithm for both parts of the whole question.
The author ultimately got the faster solution by using As instead of Ms in Part 2 and thanked the creator of the puzzle for another fun and challenging puzzle.
The problem involves grid puzzles which often suffer the obstacle of out-of-bounds indices. The author overcame this obstacle by using a 3-cell thick border for padding and opting for #2 strategies.
The typical approach to padding in grid puzzles is either adding checks to break the condition for non - existent rows or columns or padding the grid with enough rows and columns that there is no risk of going out-of-bounds.
A successful approach to Part 1 involves: finding the index of each 'X' in the grid, for each 'X', checking the next three letters in eight directions, and if the path ends up spelling 'XMAS', adding one to a running total.
In Part 2 of Advent of Code 2024 Day 4,using the 'A' alphabet instead and checking four cells diagonally adjacent to it gives the pattern for X-MAS matches.
The author's strategy was to find every 'A',check each one in a clockwise, and then check if the letters spell 'XMAS'.
The solution to Advent of Code 2024 Day 4 involves building the Set() of Stringified coordinates for each match to only account for an X-MAS instance once. Author credits usage of Word Search Puzzles strategy for this task.