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 310cefcCopy full SHA for 310cefc
2025/day08/solutions.py
@@ -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