1
vote
Day 4: Printing Department
Today's problem description: https://adventofcode.com/2025/day/4
Please post your solutions in your own top-level comment. Here's a template you can copy-paste into your comment to format it nicely, with the code collapsed by default inside an expandable section with syntax highlighting (you can replace python with any of the "short names" listed in this page of supported languages):
<details>
<summary>Part 1</summary>
```python
Your code here.
```
</details>
Finally, a character grid problem. If you've done one of these before, hopefully you've saved up some utility methods from previous years to solve this one in a snap.
Thoughts
My old utility code already had methods for (1) parsing the input into an array of chars; (2) give you an IEnumerable of all coordinates in the grid; (3) find the coordinates of the eight neighbors of a coordinate; and (4) replace the character at a coordinate. All I had to write is checking if the neighbor count of `@` is less than 4., and write a loop to replace them until we can't anymore. Nothing really challenging here, and the code runs mighty fast without the need for any micro-optimizations.
C# code
Elixir
I've built up a pretty robust
Gridmodule over the years—maybe concerningly robust given that it's used solely for a bunch of toy code puzzles—so today's solution was a quick one.No special optimizations, I just took the obvious approach.
Both parts
Benchmarks
Bonus: Final grid
I thought the grid looked neat after all of the forkliftable cells had been cleared.This is what I get for my puzzle input, it's pleasingly blobby:
Over two hours to write and over a minute to run...
Yesterday I would have said Prolog didn't seem so bad and I was getting a feel for things, today I spent the better part of an hour getting a Moore neighborhood to work.
Real tired and pretty disappointed after this one. Hopefully get a second wind with some free time this weekend.
Prolog Solution