aboutsummaryrefslogtreecommitdiff
path: root/2025/08/b.py
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-12-08 07:29:26 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2025-12-08 07:29:26 +0100
commit5d69f923116a2b251a445c0cb9e6f23551ad686a (patch)
tree42dfa409c6198f6796b4e8513d01bbdb0a00725e /2025/08/b.py
parent01c2cd358b3f693181fa86e82414b3e32f9a890e (diff)
downloadaoc-5d69f923116a2b251a445c0cb9e6f23551ad686a.tar.gz
aoc-5d69f923116a2b251a445c0cb9e6f23551ad686a.zip
Day 8 2025
Diffstat (limited to '2025/08/b.py')
-rw-r--r--2025/08/b.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/2025/08/b.py b/2025/08/b.py
new file mode 100644
index 0000000..4a6d610
--- /dev/null
+++ b/2025/08/b.py
@@ -0,0 +1,26 @@
1import fileinput
2
3with fileinput.input() as lines:
4 pts = [tuple(int(x) for x in line[:-1].split(',')) for line in lines]
5
6r = range(len(pts))
7
8def dist(p, q):
9 return (p[0]-q[0])**2 + (p[1]-q[1])**2 + (p[2]-q[2])**2
10
11d = sorted([(dist(pts[i], pts[j]), i, j) for i in r for j in r if j > i])
12
13rep = [i for i in r]
14
15def findrep(i):
16 return i if rep[i] == i else findrep(rep[i])
17
18def joinrep(i, j):
19 rep[findrep(i)] = findrep(j)
20
21for _, j, k in d:
22 if findrep(j) != findrep(k):
23 joinrep(j, k)
24 sol = pts[j][0] * pts[k][0]
25
26print(sol)

Generated with cgit - Back to sebastiano.tronto.net