Skip to content

Commit efed266

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

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

2025/day08/solutions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
12+
ds = DisjointSet(ns)
13+
for edge in edges:
14+
if edge == edges[1000]:
15+
print(prod(sorted(map(len, ds.subsets()))[-3:]))
16+
ds.merge(*edge)
17+
if ds.n_subsets == 1:
18+
break
19+
20+
print(prod(next(zip(*edge))))

0 commit comments

Comments
 (0)