Advent of Code 2024 - Day 4Ceres Search
| Problem statement | Source code | Tags: Grid walking
This problem pays tribute to 2019 day 10.
Part 1
This starts a series of days where my solution starts with the incantation:
This is the thing I really appreciate about OCaml: not only does it have arrays, but also for loops and refs. Perhaps a bit guilty, but I find imperative code much more straightforward than recursion or folds (which I spend non-trivial time rewriting into tail recursion).
Given a direction (dx, dy) and a starting point (x, y), we can walk in that direction and validate that we see X, M, A, S in order. We just repeat this for all 8 directions for each cell.
Part 2
Now for each cell, we need to search its 3x3 neighborhood for two diagonals of MAS. For each diagonal, we should see either MAS or SAM.