Advent of Code 2025 - Day 4Printing Department
| Problem statement | Source code | Tags: Cellular automata
Part 1
There are 8 neighbor positions to test, which can be iterated by enumerating the relative coordinates for row and column. For each position, check if it's in bounds and contains a @.
Part 1 just counts the cells that contain @ and have fewer than 4 @ neighbors.
Part 2
I guess, the only pitfall here is to make sure to update the grid simultaneously because earlier updates can affect tests for later cells. I save a list of cells to update, and then apply the updates after iterating through the whole grid. I stop when there are no more updates to apply.