summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormhsn <mail@mhsn.net>2025-12-23 19:50:08 +0000
committermhsn <mail@mhsn.net>2025-12-23 20:29:19 +0000
commit8165b62d55424ecd0028fabd573ae3ffe7adf458 (patch)
tree27e1c3821411c6f6e296fb4c235fc0121f25bd7b
parent2c4eec0e929ba6533b7107b795067297a47db785 (diff)
downloadaoc-8165b62d55424ecd0028fabd573ae3ffe7adf458.tar.gz
aoc-8165b62d55424ecd0028fabd573ae3ffe7adf458.zip
25-08 python p1
-rwxr-xr-x2025/08/python.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/2025/08/python.py b/2025/08/python.py
new file mode 100755
index 0000000..665aec8
--- /dev/null
+++ b/2025/08/python.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+from fileinput import input
+from math import dist, prod
+from operator import itemgetter
+
+boxes = [[*map(int, line.split(","))] for line in input()]
+N = len(boxes)
+
+js = {n: {n} for n in range(N)}
+conns = sorted(
+ ((x, y) for x in range(N) for y in range(x)),
+ key=lambda t: dist(*itemgetter(*t)(boxes)),
+)
+
+for x, y in conns[:1000]:
+ 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)