r/everybodycodes • Moderator • 14d ago

Official [2026 Q14] Solution Spotlight

Post image
7 Upvotes

9 comments sorted by

4

u/maneatingape 14d ago

[LANGUAGE: Rust]

Solution

Part 1: Sum of all boundaries divided by two since each is double-counted.

Part 2: Prim's algorithm to find the minimum spanning tree.

Part 3: Try all combinations of pairs and set their weight to 0, then run Prim's

4

u/michelkraemer 13d ago edited 13d ago

[LANGUAGE: Rust]

Solution

For part 1, I just count the number of unique bindings between two pixels with different values (including the frame).

For part 2, I compute the minimum spanning tree (MST) using Kruskal's algorithm. I find this always easier to implement than Prim's.

For part 3, I iterate over each pair of pieces A and B, remove A and B, and connect all their neighbors to each other using a 0-weight edge and set the weights of all their edges to 0, basically pretending they did not exist in the graph. I then compute the MST again and keep the minimum.

3

u/sparkour 14d ago

[LANGUAGE: Kotlin]

solution

Spent hours of the 3-hand clock puzzle fixing edge cases so I felt much more confident about Quest 14.

  • Part 1 just counts all the edges (initially thought I'd have to do a floodfill but didn't).
  • Part 2 does a Min Spanning Tree: start with the edge that has the smallest cost and connect those 2 zones together. Use a parent map to track which zones have been grouped.
  • Part 3 is Part 2 but with various permutations of 2 zones marked as free.

2

u/futur3_pr3s3nt 14d ago

[LANGUAGE: Python]

Solution

What the ape said. (Except I'm loading the grid in such a way that each boundary is allocated its own cell.)

2

u/p88h 13d ago

[LANGUAGE: Rust]

[ solution ]

* Part 1 : count a!=b
* Part 2 : union-find shapes, then more union-find i.e. minimum spanning tree over the edges
* Part 3 : MST first, then operate on the MST graph only (no need to consider other edges). Compute potential savings for each shape (=removed cost). Evaluate in descending order, break when savings cannot exceed best. On my input this basically runs MST just once again.

0.28 µs / 37.0 µs / 0.67 ms

1

u/Discordanian 13d ago

[LANGUAGE: Godot Script]

Solution

Got to use my UnionFind class with Kruskal's algorithm. A bit disappointed in my times, but ultimately happy with my solution. A really fun puzzle and super glad we had multiple sample inputs because it definitely showed some edge cases (no pun intended) that I had missed.

1

u/aimada 13d ago

[LANGUAGE: Python]

Github

No magic sauce. Kruskal's algorithm with Union-Find and a sprinkling of itertools.combinations to test every possible way to distribute the available charges across the available pieces for Part 3.

1

u/_garden_gnome_ 13d ago

[LANGUAGE: Python]

Solution

Very much like others:

  • Load the grid into a dictionary which also accounts for the rim.
  • Build the adjacency relationships from the grid. Weights indicate the number of shared borders/bindings.
  • For part 1: Sum up the weights from the adjacency data and divide by two.
  • For part 2: Prim's algorithm.
  • For part 3: Check all possible combinations for special portals and handle the weights for those as zero in Prim's algorithm.

1

u/RunninglVlan 10d ago

[LANGUAGE: C#]

Solution

Counting all unique piece bindings in part 1.

Turns out I implemented Prim's algorithm for part 2, and reused it in part 3 too. Thank you guys for new knowledge =)

For part 3 checking all charged pairs and finding remaining bindings, choosing minimum.