Skip to content

Commit ff19448

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

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

2025/day08/solutions.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from itertools import combinations
2+
from math import prod
3+
import networkx as nx
4+
5+
with open("input") as f:
6+
ls = f.read().strip().split("\n")
7+
8+
9+
ns = [tuple(map(int, l.split(","))) for l in ls]
10+
edges = sorted(
11+
(sum((x1 - x2) ** 2 for x1, x2 in zip(n1, n2)), n1, n2)
12+
for n1, n2 in combinations(ns, 2)
13+
)
14+
15+
G = nx.Graph()
16+
G.add_nodes_from(ns)
17+
for i, (_, n1, n2) in enumerate(edges):
18+
if i == 1000:
19+
# Part 1
20+
print(prod(sorted(map(len, nx.connected_components(G)))[-3:]))
21+
G.add_edge(n1, n2)
22+
if nx.is_connected(G):
23+
# Part 2
24+
print(n1[0] * n2[0])
25+
break

0 commit comments

Comments
 (0)