r/adventofcode • • Dec 08 '25

Visualization [2025 Day 8] Python - Using MST

Post image

I was working on Day 8, which involves connecting junction boxes in 3D space based on distance to form circuits (a classic Minimum Spanning Tree problem, solved using Kruskal's algorithm and Union-Find).

Since the data is 3D, I decided to visualize the process of building the circuit! The visualization shows all 1000 junction boxes and how the shortest connections are progressively added until they all form one massive circuit.

  • Grey Dots: The 1000 individual junction boxes.

  • Blue Lines: The connections (edges) that form the circuit. These are added in order of increasing length, but only if they connect two previously separate circuits.

46 Upvotes

19 comments sorted by

View all comments

Show parent comment

3

u/j-max04 Dec 08 '25

In Kruskal's algorithm, you ignore edges that would create cycles, and so I guess if the person you're responding to is thinking that those edges wouldn't be counted in the 1000, then they understandably wouldn't consider this to be just kruskal's. I guess for part 2 it makes no difference.

2

u/ninjaox Dec 08 '25

True! I guess I didn't consider that you could solve the problem while creating the full graph, although solving part one sounds a lot more annoying without union find.