Everybody Codes, the 2025 event, quest 6-10

I’ve done Everybody Codes, back in November.

The Song of Ducks and Dragons [ 2025 ]

All my code is available .

AaAaa 
AaAaa
AaAaa
AaAaa
AaAaa

Quest 6. Given a list of letters, find all pairs of e.g. “A*a” (part 1 and 2). Repeating the list 1000 times, do it again (part 3).

Part 1 was nice actually. Going through the list, there’s a counter for how many “A”s I’ve seen so far. And when I encounter an “a”, I add that counter value to the running sum. Part 2 was a little more sophisticated, where it had to work without me knowing what letter I was actually looking at. And using ctype_upper() and strtoupper(). Oh, part 3. Here I could use the knowledge, that repeating the list also meant repeating the numbers. With 1000 repetitions, 998 of them are “in the middle”. Count 1 of these and multiply by 998. Then count the 1st and the last. It was a little fiddly. For some reason I didn’t just create my own example data and work on that.

Oronris,Urakris,Oroneth,Uraketh

r > a,i,o
i > p,w
n > e,r
o > n,m
k > f,r
...

Quest 7. Given a list of names and a list of rules, which names follow all the rules (part 1 and 2)? Like, Oronris is out, because s can’t follow i. Then construct all names possible with the rules (part 3).

For part 1 and 2, look at each pair of letters and check whether that exists as a rule. For part 3, oh, recursion. Given part of a name, add all the possible next letters. And check uniqueness, which I didn’t at first!

1,5,2,6,8,4,1,7,3

Quest 8. Given a list of numbers, interpret these as the numbers of nails. So in this list, there’s a string between 1 and 5, between 5 and 2 etc. How many times does a string pass through the center of the circle of nails (part 1)? How many times does a string cross another string (part 2)? Which extra string would cross the most existing strings (part 3)?

The 1st one is easy. Calculate the distance between the 2 nails. If the distance is the same as halfway around the circle, the string will go through the center. In part 2 I use this knowledge: If 2 strings, 1 -> 5 and 7 -> 3, cross each other, it’s because 1 < 3 < 5, but not 1 < 7 < 3. I also have to take care of the edge case, where “both strings use the same nail in 1 end” isn’t counted as crossing. In part 3 I use some of my existing program, but also create all the possible strings. The one I’m looking for might not already exist.

1:CAAGCGCTAAGTTCGCTGGATGTGTGCCCGCG
2:CTTGAATTGGGCCGTTTACCTGGTTTAACCAT
3:CTAGCGCTGAGCTGGCTGCCTGGTTGACCGCG

Quest 9. So called DNA sequences. We have 3 of these, 2 parents and 1 child. For each letter in the sequence, the child should have the same letter as 1 of the parents. Which 1 is the child (part 1 and 2)? Construct a family tree for a lot of people, and measure the largest family (part 3).

Pretty straight forward coding. Can this person be the child of these 2 persons, yes or no? With more than 3 persons, have a 2d array, $children[$parent1][$parent2] = $child. In part 3 I begin by saying all triples are small families. Then I combine these into larger families, until they can’t grow anymore. I got to use “break 3”.

.......       ...X...       ......D       .......       .......
..X.X.. .D..... ....X.. ....... ....X.X
.X...X. ...X... .....X. ....... ...X...
...D... X.X.... ....... ....... .....D.
.X...X. ....... ....... ..X.X.. ...X...
..X.X.. ....... ....... .X...X. ....X.X
....... ....... ....... ...D... .......

Quest 10. Given a map, that’s actually sort of a chessboard, with D marking a dragon moving like a knight, and S marking sheep (no sheep shown above), how many sheep can the dragon reach and eat (part 1)? Add that the sheep can also move and can hide (part 2). Find all games where the dragon eats all the sheep (part 3).

I can see in part 3 I added memoization. And I borrowed code heavily from a colleague. It was hard to keep it straight in my head, where did the dragon go, where did the sheep go, when did a game end with all sheep eaten. On, there’s also recursion.

Everybody Codes, the 2025 event, quest 1-5

I’ve done Everybody Codes, back in November. And I got all 60 stars, yeah me! 3 of the stars I only got recently, as among other things Advent of Code and mscroggs arrived in December. Nevertheless!

The Song of Ducks and Dragons [ 2025 ]

All my code is available . I aim for low complexity, easily readable code. Including comments. And it’s in PHP.

       Vyrdax
/ \
/ \
Elarzris Drakzyph
\ /
\ /
Fyrryn

Quest 1. Given a list of names, move left and right through the list (part 1). With wrapping (part 2). Or instead of moving around, swap names (part 3).

Create a system to keep track of positions. Use %. Use arrays.

A = [25,9]
R = [ 0,0]

Cycle I
R = R * R = [0,0]
R = R / [10,10] = [0,0]
R = R + A = [25,9]

Quest 2. Given a number, perform a well defined set of math instructions on that number (part 1). Given a map of points, all with coordinates, perform those math instructions of each point (part 2). (Makes a nice picture.) Increase size of map (part 3).

A lot of math. A 2d array.

10,5,1,10,3,8,5,2,2

10 > 8 > 5 > 3 > 2 > 1 the sum of the sizes: 10 + 8 + 5 + 3 + 2 + 1 = 29
10 > 8 > 5 > 2 > 1 the sum of the sizes: 10 + 8 + 5 + 2 + 1 = 26
10 > 5 > 3 > 2 the sum of the sizes: 10 + 5 + 3 + 2 = 20
10 > 5 > 2 the sum of the sizes: 10 + 5 + 2 = 17

Quest 3. Given a list of numbers, create a new list of distinct numbers with the highest sum possible (part 1). Or a list with 20 distinct numbers and the smallest sum possible (part 2). Or the lowest number of lists, covering everything from the original list.

In part 1, simply throw away the duplicates. array_unique(). In part 2, sort the unique numbers and keep the 20 smallest. In part 3, count occurrences of each number and register the largest. array_count_values(). max().

128
64
32
16
8

Quest 4. Interpret a list of numbers as teeth on neighboring gears. If the 1st gear turns 2025 times, how many times does the last gear turn (part 1)? If the last gear turns 10000000000000 times, how many times does the 1st gear turn, rounded up (part 2)? Or do the part 1 calculation again, but with more complicated gears with 2 sets of teeth (part 3).

In part 1 I calculate how many teeth were involved for the 1st gear, and then calculate how many turns that is for the last gear. Part 2 is the same in reverse. In part 3 I did the full calculation, involving all the gears.

 3-5-7
|
1-8-10
|
5-9
|
7-8

Quest 5. The fishbone! Given a list of numbers, construct the valid fishbone. Then make other choices based on the result.

As I was basically doing the same thing a lot, I was quick to put stuff into functions. That actually became a guiding principle. If part 2 was “do the same as part 1, but a lot of times”, create a function. A fun function to use was usort(), a custom sorting function. Not very complicated code, just fiddly.

I am also finding a rhythm. I usually build 1 large program, because later parts don’t require a complete rewrite of earlier work. And I get used to the input for the 3 parts being different.

Advent Of Code

#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 🙂🙂

Hamilton gyrates

Recently I rewatched #Hamilton and was fascinated by the gyrations of some of the men. I think this little dance move is clever in signaling rock-‘n’-roll, drugs and above all s*x.

A Winter’s Ball. Looking for ladies. Hamilton, Burr, Laurens.

Helpless. Hamilton has proposed to his future wife, and her father approves of the connection. And then Hamilton does this little move, before he remembers the situation.

The Story Of Tonight, Reprise. Laurens, Lafayette and Mulligan are teasing the groom.

Advent of Code, 2025, animations

This year, apart from solving the #AdventOfCode puzzles (24 stars, yeah!), I also made #animations for each day.

I’m trying to make an animation, that can work on its own. You should be able to watch it, deduce the puzzle and understand the solution.

I use example data. It varies whether I show a full or partial solution, and whether I show part 1 or 2.

I’m using ASCII art, because it’s easy for my PHP scripts to produce it. Also, there’s a certain charm to 24×80, right?

Here’s the playlist . Enjoy!

#ThisWeeksFiddler, 20251219

This week the #puzzle is: Happy (Almost) New Year from The Fiddler! #MagicSquare #primes

A magic square is a square array of distinct natural numbers, where each row, each column, and both long diagonals sum to the same “magic number.” ,,,
A prime magic square is a magic square consisting of only prime numbers. Is it possible to construct a 4-by-4 prime magic square with a magic number of 2026? If so, give an example; if not, why not?

And for extra credit:

Find all values of N for which it is possible to construct an N-by-N prime magic square with a magic number of 2026. (Remember, the numbers in a magic square must all be distinct!)

Happy (Almost) New Year from The Fiddler!

Highlight to reveal (possibly incorrect) solution:

Examples of prime magic squares OEIS sequence Magic Squares (4 x 4), Analytic Solution, Pan Magic Squares Prime Magic Squares (4 x 4), Simple Magic Squares (4 x 4) Magic Square Generator

Program

Example of a magic square with magic sum 2026:
Example of a prime magic square with magic sum 240:

50650951249947779107
511500505510371013171
50151450750473198959
50850350251383113413

And for extra credit:

#ThisWeeksFiddler, 20251212

This week the #puzzle is: Can You Topple the Tower? #geometry #trigonometry #CenterOfMass #integral

A block tower consists of a solid rectangular prism whose height is 2 and whose base is a square of side length 1. A second prism, made of the same material, and with a base that’s L by 1 and a height of 1, is attached to the top half of the first block, resulting in an overhang as shown below.
When L exceeds some value, the block tower tips over. What is this critical length L?

And for extra credit:

Instead of rectangular prisms, now suppose the tower is part of an annulus. More specifically, it’s the region between two arcs of angle 𝜽 in circles of radius 1 and 2, as shown below.
For small values of 𝜽, the tower balances on one of its flat sides. But when 𝜽 exceeds some value, the tower no longer balances on a flat side. What is this critical value of 𝜽?

Can You Topple the Tower?

Intermission

Last week I was busy. ( #AdventOfCode ) I misread the description of the puzzle, and by the time I realized my error, I didn’t have enough time left to fix my mistake. So it goes.

Highlight to reveal (possibly incorrect) solution:

Geeks for Geeks Allen Desmos

And for extra credit:

#ThisWeeksFiddler, 20251128

This week the #puzzle is: Can You Take the Heat? #combinatorics #coding #recursion

In the YouTube show, “Hot Ones,” guests answer interview questions while consuming 10 hot sauces, one at a time, ranked in increasing spiciness from 1 to 10.
You have been invited on as a guest and want to prepare for the show. However, you don’t feel like purchasing all 10 sauces in advance. Your plan is to purchase fewer sauces, and then to combine sauces together for any you are missing. For example, if you are missing sauce #7, then you can instead simultaneously consume sauces #3 and #4, since 3 + 4 = 7. (I know the spiciness of the sauces isn’t linear, but for the purposes of this puzzle, let’s assume it is.)
After some pencil-and-paper scratch work, you realize you only need four spices.
… for how many sets of four spice numbers is it possible to generate all the numbers from 1 to 10 using each spice at most once?

And for extra credit:

You’re prepping for a new show, “Hotter Ones,” which has spices ranked from 1 to 100. Let N be the minimum number of spices needed to generate all the numbers from 1 to 100.
For how many sets of N spice numbers is it possible to generate all the numbers from 1 to 100 using each spice at most once? (Note that I am not asking for the value of N; that’s just something you’ll need to figure out en route to your answer.)

Can You Take the Heat?

Highlight to reveal (possibly incorrect) solution:

Program

And for extra credit: