Skip to content

Commit fe67250

Browse files
committed
Added day 8
1 parent 5174663 commit fe67250

3 files changed

Lines changed: 58 additions & 8 deletions

File tree

aoc/2025/08/08.vn.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Advent of code Day 08
2+
# https://adventofcode.com/2025/day/8
3+
# 08/12/2025
4+
5+
from tqdm.auto import tqdm
6+
7+
with open("input.txt") as file:
8+
inp = list(
9+
map(
10+
lambda s: tuple(
11+
map(
12+
int, s.strip().split(",")
13+
)
14+
),
15+
file.readlines()
16+
)
17+
)
18+
19+
edges = []
20+
parent = [i for i in range(len(inp))]
21+
size = [1 for _ in range(len(inp))]
22+
23+
for i, (x1, y1, z1) in tqdm(enumerate(inp), desc="Adding edges"):
24+
for j, (x2, y2, z2) in enumerate(inp[i+1:], start=i+1):
25+
cost = (x2-x1)**2 + (y2-y1)**2 + (z2-z1)**2
26+
edges.append(
27+
(cost, i, j)
28+
)
29+
edges.sort()
30+
31+
def find(a):
32+
if parent[a]!= a:
33+
parent[a] = find(parent[a])
34+
return parent[a]
35+
36+
def union(a, b):
37+
root1 = find(a)
38+
root2 = find(b)
39+
parent[root2] = root1
40+
size[root1] += size[root2]
41+
size[root2] = 0
42+
43+
44+
res1, res2 = 0, 0
45+
cpt, wanted = 0, 1000
46+
for edge in tqdm(edges, desc="Computing res"):
47+
if cpt == wanted:
48+
a, b, c = sorted(size, reverse=True)[:3]
49+
res1 = a*b*c
50+
cost, vertexA, vertexB = edge
51+
cpt += 1
52+
if find(vertexA) != find(vertexB):
53+
union(vertexA, vertexB)
54+
# We just need the last res2
55+
res2 = inp[vertexA][0] * inp[vertexB][0]
56+
57+
58+
print(res1, res2)

aoc/2025/08/animated/08_animated.vn.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

aoc/2025/08/normal/08_normal.vn.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)