Skip to content

Commit 07425b3

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

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

2025/day08/solutions.py

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

0 commit comments

Comments
 (0)