#AdventOfCode 2025
has been. This year I solved all the puzzles within 24 hours of publication (details at the end of this post). Yeah me! And I was reasonably happy with my code (PHP)
. And I made animations for all 12 days!

Day 1: Spin a dial left or right, counting how many times it hits 0. Or passes 0.
It was fiddly to get the “passes 0” bit right. And how can % ever return a negative number?

Day 2: Search an interval of integers for numbers constructed by concatenating the same sequence of digits together 2 times. Or n times.
So. If we’re currently looking at the interval 95-115, 99 should be detected, because it’s “9” twice. Part 1 was very easy. In part 2 I had to give up doing part 1 and 2 simultaneously. Part of the solution was to treat numbers as strings, some of the time. PHP made that very easy.

Day 3: Given a number, find the highest 2 digit extract. Or 12 digit.
I think I wrote part 1 as brute force and then changed it for part 2. Key insight: If I’m looking for a digit, that will end up as e.g. the 7th digit of the result, counting from the back, it can’t be 1 of the last 6 digits of the number, because they may have to be the last 6 digits. Let’s say that leaves 5 digits. (I may have already used some of the preceding digits for the start of the result.) Then the optimal solution is to choose the highest digit of those 5. If that digit occurs more than once, choose the leftmost, to leave as many candidates as possible for the next digits. Also, recursion.

Day 4: On a map with “@”, given certain rules, remove as many “@”s as possible. For 1 round. Or until nothing more can be removed.
I included a cute ASCII art forklift (the @ are removed with a forklift) in the animation. 🙂
The suggested solution was to mark @ to be removed as x and then remove them. For part 2 I changed between x and y. That allowed me to mark removal with x in a round and then do the actual removal in the next round.

Day 5: Given an integer and an interval, check whether the integer fits in the interval. E.g., does 11 fit in the interval 10-14? (Yes.) In part 2, count how many integers could potentially fit the given intervals.
For part 1: Brute force. For part 2: First merge the intervals, then simply calculate their lengths and sum. That merging required brain power.

Day 6: Given some numbers and a way to manipulate them (e.g., multiplication), calculate a result. 123*45*6 = 33210. In part 2, look at the numbers vertically. 1*24*356.
Array manipulation. In part 2 I was lucky I could recycle a function, that pivots a 2d array. That made it very easy.

Day 7: A beam travels. When it meets a “^”, it splits into 2. Count how many splits occur. In part 2, count how many different paths a beam could travel.
Part 1 was easy. Scan downwards on the map, adding the beams and counting splits. In part 2 I had to keep track of the beams. If e.g. 4 beams arrived here, simply traveling down, and 3 more beams arrived after a split on my right, 7 beams are traveling through here. At the bottom I add up all the beams.

Day 8: Some points in 3d space have to be connected. Do a number of connections and then find the largest connected groups. In part 2, connect everything and note which 2 points were the last to be connected.
I guess my biggest challenge here was to keep track of “which group does this point belong to” and “which points are in this group”. I had the right idea, but I had some mishaps with using the wrong variable names.

Day 9: Given a number of points in 2d space, construct the largest rectangle possible using 2 of the points as opposite corners. Seeing the points as the corners of a polygon, check whether the rectangle fits inside the polygon.
Part 1 was pretty straightforward. I had learned some new notation: [$x1, $y1] = $data[$i]. In part 2 I could recycle some code from year 2023, day 10: Given a map of a polygon, find all points within that polygon. I also converted the points given into an actual map. I made a list of the x- and y-coordinates used by the points, plus their immediate neighbors. When traveling across my map, I needed to look at immediate neighbors, but I could skip over long distances of uninteresting coordinates. What else? Oh, given the input
I could deduce quickly that some rectangles wouldn’t work. And I used memoization to ensure I only checked each point once, regarding what type the point was (corner, edge, inside polygon).

Day 10: So. There are some lights. There are also some buttons. Each button toggles one or more lights. There is a target for which lights should be on. Find the best button combination. In part 1, each button could be pressed at most once, easy. Brute force, recursion. In part 2… Even with the key insight, that we were actually looking for the best solution to a set of equalities, I was stumped. I ended up writing code to produce a Python script, because Python has a library to solve that kind of thing.

Day 11: Given a network, how many ways to travel from a to b. Or from a to b via c and d.
I really like my animation for this day.
Part 1: Brute force, recursion. Part 2: Ehm. Key insight: Figure out whether it’s possible to go from c to d or the other way around. Say it’s d to c. Then count ways to get from a to d, d to c and c to b. Then multiply. Also memoization.

Day 12: Given a rectangle and a number of heptaminos, check whether they fit. It turned out, heurestics were important this day. Each heptamino uses 7 small squares, are there that many in the rectangle? If not, no fit. Each heptamino fit inside a 3×3 square, are there that many in the rectangle? If yes, fit.
Day 1-12: I have used the forums here and there for inspiration. On 1 occasion I would say I stole part of a solution (Python day), but in a way where I understood what I was stealing.
And the times — some days I couldn’t get to the puzzle early:
Day -Part 1- -Part 2-
12 04:29:58 04:30:36 🙂🙂
11 03:35:59 11:59:01 🙂
10 05:06:05 11:57:11 🙂
9 01:00:09 06:16:55 🙂
8 06:01:56 06:13:01 🙂🙂
7 13:32:56 13:49:21 🙂
6 03:17:52 03:39:24 🙂🙂
5 02:53:13 03:43:01 🙂🙂
4 02:50:27 03:09:28 🙂🙂
3 01:14:49 05:25:54 🙂
2 05:57:58 06:16:42 🙂🙂
1 01:31:57 02:13:48 🙂🙂