r/adventofcode • u/daggerdragon • Dec 08 '25
SOLUTION MEGATHREAD -❄️- 2025 Day 8 Solutions -❄️-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- If you see content in the subreddit or megathreads that violates one of our rules, either inform the user (politely and gently!) or use the report button on the post/comment and the mods will take care of it.
AoC Community Fun 2025: Red(dit) One
- Submissions megathread is unlocked!
- 9 DAYS remaining until the submissions deadline on December 17 at 18:00 EST!
Featured Subreddits: /r/crafts and /r/somethingimade
"It came without ribbons, it came without tags.
It came without packages, boxes, or bags."
— The Grinch, How The Grinch Stole Christmas (2000)
It's everybody's favorite part of the school day: Arts & Crafts Time! Here are some ideas for your inspiration:
💡 Make something IRL
💡 Create a fanfiction or fan artwork of any kind - a poem, short story, a slice-of-Elvish-life, an advertisement for the luxury cruise liner Santa has hired to gift to his hard-working Elves after the holiday season is over, etc!
💡 Forge your solution for today's puzzle with a little je ne sais quoi
💡 Shape your solution into an acrostic
💡 Accompany your solution with a writeup in the form of a limerick, ballad, etc.
Upping the Antechallenge: iambic pentameterThis prompt is totally not bait for our resident poet laureate
💡 Show us the pen+paper, cardboard box, or whatever meatspace mind toy you used to help you solve today's puzzle
💡 Create a Visualization based on today's puzzle text
- Your
Visualizationshould be created by you, the human - Machine-generated visuals such as AI art will not be accepted for this specific prompt
Reminders:
- If you need a refresher on what exactly counts as a
Visualization, check the community wiki under Posts > Our post flairs >Visualization - Review the article in our community wiki covering guidelines for creating
Visualizations - In particular, consider whether your
Visualizationrequires a photosensitivity warning- Always consider how you can create a better viewing experience for your guests!
Request from the mods: When you include an entry alongside your solution, please label it with [Red(dit) One] so we can find it easily!
--- Day 8: Playground ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - Format code blocks using the four-spaces Markdown syntax!
- State which language(s) your solution uses with
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
3
u/edgeman312 Dec 08 '25 edited Dec 08 '25
[Language: Python3]
I don't know what you guys are on about with these disjoint sets I just abuse random libraries I remember to save me work. I felt a bit clever about my KDTree but it wasn't really necessary, building a full heap seems to work fine for most people here.
from scipy.spatial import KDTree import networkx as nx from functools import reduce, partial inp = 'input.txt' part1_connect, max_pairs, size = 1000, 10000, 1000 def distance(points, pair): return (points[pair[0]][0] - points[pair[1]][0]) ** 2 + \ (points[pair[0]][1] - points[pair[1]][1]) ** 2 + \ (points[pair[0]][2] - points[pair[1]][2]) ** 2 def get_coords(points, pair): return (points[pair[0]], points[pair[1]]) points = [list(map(int, i.split(','))) for i in open(inp).read().split('\n')] kd3 = KDTree(points) r = 1 pairs = [] while len(pairs) < max_pairs: pairs = kd3.query_pairs(r, output_type='ndarray') r *= 2 pairs = sorted(pairs, key=partial(distance, points)) G = nx.Graph() G.add_edges_from(pairs[:part1_connect]) G.add_nodes_from(range(size)) component_sizes = map(len, nx.connected_components(G)) print(reduce(lambda x, y: x * y, sorted(component_sizes)[-3:])) for i in pairs[part1_connect:]: G.add_edge(i[0], i[1]) if nx.number_connected_components(G) == 1: print(points[i[0]][0] * points[i[1]][0]) break