Everybody Codes is now in its
third year, and I've been doing it again.
All of my code is on Codeberg.
[Day 11](https://everybody.codes/event/2026/quests/11
Hello pathfinding my old friend! (And hello pathfinding crate.)
The strain before extra links looks as though it ought to be readily
calculable, but it's not trivial enough for me, so I throw it all at
dijkstra_all and see what sticks. For part 1: build the
circumferential network, calculate the strain on one node and multiply
by number of nodes. For part 2: add the crosslinks, calculate the
total available path lengths from each point (technically to each
point, with Dijkstra, but it's all symmetrical). Then take the
difference.
For part 2, as above, but then iterate over all possible optional
crystal positions; for each set, clone the network, insert the links,
calculate the resonance. (Fortunately dijkstra_all is heavily
optimised and runs very fast.)
For part 3, basically as for part 2, but with a horrible 9-deep loop.
(First node location which sets all the others, then each possible
pair.) Yeah, I could have optimised this further and indeed done it as
a proper BFS, but I put in (a) some basic deduplication and (b) a
guard set that makes sure all eight parameters are distinct before it
does the dijkstra_all as above, and it worked in short order, so
job's a good 'un.
(A counter revealed that the loop got as far as the call to
dijkstra_all 420 times for the n=32 example, 840 for n=64. and 1050
for the problem data n=80. Which is 13⅛ evaluations per node, which
is… an interesting number.)
[Day 12](https://everybody.codes/event/2026/quests/12
This wiggled around quite a bit between stages.
Part 1: store valid coordinates in a grid, copied to a set. Iterate
through that grid, looking only at coordinates that still exist in the
set (so each new coordinate pair I spot is a top left corner), and
from there look along the row and column to get the dimensions of the
rectangle. Score the lower one, and delete them all from the grid.
Part 2: OK, my Dir and Coord classes come back. Explore the grid
by repeatedly starting at a random set point, then go out in all
directions to fill in a shape. Then I analyse it by counting cells per
row, and per column. If there are no differences, then it's a
rectangle, and score min(x, y) as above. Otherwise, start with that,
but consider for each cell count the number of cells with the higher
value, plus the lower value.
So for example the L-shaped stack in the upper right of the example
has a bounding box of 7 × 6. Cell count values by row are (6, 6, 6, 2,
2, 2); so the block of 6s can be removed in 3 actions and the block of
2s in 2, total 5. Row count values as (3, 3, 3, 3, 3, 6, 6); the 6s
can be removed in 2 actions and the block of 3s in 3, total 5. So
overall we score 5.
But it's goodbye to short-cuts for part 3, which took A While. I find
individual shapes as before (and this means I don't need to care about
whether a shape is inside another). But then I do an over-complex
dijkstra pathfinding on that shape, starting with the set of
coordinates and ending with the empty set, and each step can lead to
four options: carve off the top or bottom row (from the left), or
carve off the left or right column (from the top). Because the crate
needs something hashable, my nice neat sets are converted into sorted
vectors of coordinates within the pathfinding and back to sets when I
want to work with them. I'm sure there are prettier ways to do this,
but I was getting frustrated.
[Day 13](https://everybody.codes/event/2026/quests/13
I took ages over the first part of this, but my solution turned out to
be robust enough to solve parts 2 and 3 as well.
The numbers I'll actually use for each hand are "angle" (the initial
position on a common scale that's the lcm of the individual numbers of
divisions) and "velocity" (the signed number of scale divisions to
move each cycle). So the first stage is to calculate those.
The only significant times are 0 and each "move" value (that's when
velocity drops to zero for at least one hand). So between each
adjacent pair of times the velocities are constant.
For each hand I calculate a delta (the total change in position,
measured in scale divisions, ignoring wrapping).
Then for each pair of hands I calculate the number of crossings, the
absolute difference between (the difference between new positions in
full rotations) and (the difference between old positions in full
rotations), plus a tweak in each case. (This took a lot of tweaking
and I'm still not completely sure I have it right, but it gets the
right answer.)
Then reset the angle for the next time interval, and continue.
[Day 14](https://everybody.codes/event/2026/quests/14
Three pleasingly distinct parts today. (And I never actually got asked
to calculate the perimeter length of an irregular shape, which makes me happy.)
For part 1, part of the cost is the total outside perimeter length
2 × (x + y). Then I walk the grid: for each element with a neighbour
above or to the left, check whether that's a different element, and if
so score an extra point.
Part 2 is that rare pathfinding that isn't a Dijkstra; in fact it's a
minimum spanning tree. I've never had to do this in real life, but I
remembered it had come up in another programming problem (in fact one
from Everybody Codes 2024) where I used Kruskal. So I did that again.
The edge "length" in this case is the cost in bindings to connect a
pair of nodes, and I transform it from my hash of hashes into a vec of
triplets. (I also need a char value that won't be used, to represent
the outer edge, and choose £ on the basis that it doesn't fit in
ASCII but is easy to type on my UK keyboard.) Then I throw that at the
Kruskal solver in pathfinding and pull out the total length of the
valid edges.
Part 3 then sophisticates that: I can pick two nodes (not including
the outside space, though I've been regarding it as a node for this
purpose), and set all their link costs to zero. Which I do
exhaustively, running Kruskal on each modified network and returning
the lowest total cost.
And just in case you were looking at your input, filtering by the
alphabetic characters produces:

I like these small touches.

[Day 15](https://everybody.codes/event/2026/quests/15
Phew! This was a very long slog. (And in fact I set it aside and did
day 15 before I'd got a working answer for part 2.)
For part 1: build a list of "sides" (passages from central spine to
central spine with non-zero amounts of sulphur in them). Then iterate:
from the last point I reached, find the nearest start point to the
left, or if none, the nearest to the right, traverse it, and delete it
from the map. In retrospect I'm not entirely convinced that this
should work.
For part 2: time to Dijkstra! Cost is distance to get to the start of
the arc plus length of the arc, and node ID is a tuple of X posiion,
last direction, and amount of sulphur gained. (This is how I solve the
problem with Dijkstra, which just minimises total cost between nodes.)
This was probably what took longest; I tried to do a BFS but it
exploded at me because I didn't have a way to avoid repetitions.
For part 3: I wanted to identify the cycle with the highest sulphur
per time, repeat that for a whole bunch of cycles until I'd nearly
reached the goal, then throw the remaining manageable goal at the part
2 solver. But, while finding a single side passage plus return down
the middle was fine for the test data, the live data's highest-rated
cycle was double-sided, so I had to look for those as well. (I might
have looked for triple side cycles if that hadn't worked…)
Probably the puzzle I've liked least so far.
I am amused, however, by inventing a new method of double-iterating
over a vec v while never having vc1 and vc2 equal (and, since the
processing is symmetrical, cutting out half of the combinations that
are reverses of the other half). What I'd usually do is something
like:
for i in 0 .. v.len() - 1 {
let vc1 = v[i];
for j in i + 1 .. v.len() {
let vc2 = v[j];
// do stuff to vc1 and vc2
}
}
but instead I came up with:
for (i, vc1) in v.iter().enumerate() {
for vc2 in v.iter().skip(i + 1) {
// do stuff to vc1 and vc2
}
}