summaryrefslogtreecommitdiff
path: root/2025/08/python.py
diff options
context:
space:
mode:
authormhsn <mail@mhsn.net>2025-12-23 20:29:26 +0000
committermhsn <mail@mhsn.net>2025-12-23 20:38:22 +0000
commit5e588a11e5d54c65f644f837b9aa38475f518b39 (patch)
tree09dad244d3919424352d75603533fede7b2247e0 /2025/08/python.py
parent8165b62d55424ecd0028fabd573ae3ffe7adf458 (diff)
downloadaoc-5e588a11e5d54c65f644f837b9aa38475f518b39.tar.gz
aoc-5e588a11e5d54c65f644f837b9aa38475f518b39.zip
25-08 python p2
Diffstat (limited to '2025/08/python.py')
-rwxr-xr-x2025/08/python.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/2025/08/python.py b/2025/08/python.py
index 665aec8..98a4725 100755
--- a/2025/08/python.py
+++ b/2025/08/python.py
@@ -4,6 +4,8 @@ from fileinput import input
from math import dist, prod
from operator import itemgetter
+MAX_CONNS = 1000 # test: 10, input: 1000
+
boxes = [[*map(int, line.split(","))] for line in input()]
N = len(boxes)
@@ -13,15 +15,15 @@ conns = sorted(
key=lambda t: dist(*itemgetter(*t)(boxes)),
)
-for x, y in conns[:1000]:
+for n, (x, y) in enumerate(conns):
+ if n == MAX_CONNS:
+ lens = {id(j): len(j) for j in js.values()}.values()
+ print("silver:", prod(sorted(lens, reverse=True)[:3]))
+
j = js[x] | js[y]
for b in j:
js[b] = j
-lens = {id(j): len(j) for j in js.values()}.values()
-
-silver = prod(sorted(lens, reverse=True)[:3])
-gold = 0
-
-print("silver:", silver)
-print("gold:", gold)
+ if len(j) == N:
+ print("gold:", boxes[x][0] * boxes[y][0])
+ break