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 07425b3Copy full SHA for 07425b3
2025/day08/solutions.py
@@ -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