We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0daaa3d commit efed266Copy full SHA for efed266
2025/day08/solutions.py
@@ -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