Skip to content

Commit 310cefc

Browse files
committed
Add solution to 2025-12-08
1 parent 0daaa3d commit 310cefc

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

2025/day08/solutions.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from itertools import combinations
2+
from math import dist, prod
3+
4+
from scipy.cluster.hierarchy import DisjointSet
5+
6+
with open("input") as f:
7+
ls = f.read().strip().split("\n")
8+
9+
ns = [tuple(map(int, l.split(","))) for l in ls]
10+
edges = sorted(combinations(ns, 2), key=lambda pair: dist(*pair))
11+
target = edges[1000]
12+
13+
ds = DisjointSet(ns)
14+
while ds.n_subsets > 1:
15+
if (edge := edges.pop(0)) == target:
16+
print(prod(sorted(map(len, ds.subsets()))[-3:]))
17+
ds.merge(*edge)
18+
19+
print(prod(next(zip(*edge))))

0 commit comments

Comments
 (0)