Skip to content

Commit c9523cf

Browse files
committed
Add day08, 2025
1 parent 4c883ea commit c9523cf

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

2025/day08/solution.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from itertools import combinations
2+
import networkx as nx
3+
4+
5+
with open("input") as f:
6+
inp = f.read().strip().split("\n")
7+
8+
boxes = [tuple(map(int, line.split(","))) for line in inp]
9+
10+
dists = [
11+
(sum((x - y) ** 2 for x, y in zip(p1, p2)), p1, p2)
12+
for p1, p2 in combinations(boxes, 2)
13+
]
14+
15+
dists.sort(key = lambda x: -x[0])
16+
17+
g = nx.Graph()
18+
i = 0
19+
while dists:
20+
_, p1, p2 = dists.pop()
21+
g.add_edge(p1, p2)
22+
comps = list(nx.connected_components(g))
23+
if (i := i + 1) == 1000:
24+
sizes = sorted(list(map(len, comps)), reverse = True)
25+
print(sizes[0]*sizes[1]*sizes[2])
26+
if len(comps) == 1 and len(g.nodes()) == len(inp):
27+
print(p1[0]*p2[0])
28+
break

0 commit comments

Comments
 (0)