Vigyata.AI
Is this your channel?

ADVENT OF CODE 2024 | Day 4 *realistic* Grid Traversal Algorithm | Jackie's Solution

6.5K views· 220 likes· 6:08· Dec 6, 2024

Subscribe for more content like this :) 0:00 coding challenge 1:18 PART 1 solution 3:28 PART 2 solution #adventofcode #vlogmas #programming

About This Video

In this Advent of Code 2024 Day 4 video, I walk through my (very realistic) approach to a word search grid traversal problem. The goal for Part 1 is to find “XMAS” in a grid in all directions—left to right, bottom to top, and diagonals—basically anywhere it can hide. I originally tried to use DFS, but honestly I think I forgot how to write recursive algorithms properly, so I pivoted to an iterative grid traversal with a directions array. I show how I parse the input into a matrix, loop through every cell, and then check eight possible directions around each character. The key helper is my “isValidDirection” function: it verifies we stay within bounds and that the next letters match what we need for the keyword. That approach got me the correct answer for Part 1. Then we get to Part 2… and yes, I have beef with Part 2. The pattern changes to a crossed “MAS” shape, and I tried to hard-code the coordinate offsets for the cross and validate those positions. My logic clearly isn’t right because I’m getting zero matches, which I’m pretty sure is wrong. I share what I attempted anyway, then call it for the night because I had to go into the office the next day—so please tell me in the comments how you solved Part 2 and what I’m missing.

Frequently Asked Questions

🎬 More from CS Jackie