From 8fbd267d99b07bbf90856acb18da465fc569b515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Mon, 8 Dec 2025 07:56:36 +0100 Subject: [PATCH] Solve 2025 day 8 pt 1-2 For the First time this season, pt 2 was not an epic HOLY SHIIIT!!! facemelter. I stared at my code in disbelief during pt 1 for several minutes before I increased the test point from from 40 to 1000 and got the right answer. --- 2025-python/output/day_08.py | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 2025-python/output/day_08.py diff --git a/2025-python/output/day_08.py b/2025-python/output/day_08.py new file mode 100644 index 0000000..a1aa697 --- /dev/null +++ b/2025-python/output/day_08.py @@ -0,0 +1,58 @@ +from math import sqrt +from itertools import combinations + +from output import ints + + +def solve(data): + Di = sorted( + map(_euclidan_distance, combinations(data.splitlines(), r=2)), + key=lambda r: r[1], + ) + C = [] + S = len(data.splitlines()) + IP = 1000 + for i, pq in enumerate(Di, start=1): + pq, _ = pq + c = set(pq) + p, q = pq + rmq = [] + nothing = False + for j in C: + if p in j and q in j: + nothing = True + continue + if p in j or q in j: + c = c | j + rmq.append(j) + C = [e for e in C if e not in rmq] + if c == pq and nothing: + continue + if len(c) == S: + p2 = ints(p)[0] * ints(q)[0] + break + C = [c] + C + if i == IP: + a, b, c = sorted(list(map(len, C)), reverse=True)[:3] + p1 = a * b * c + return p1, p2 + + +def _euclidan_distance(pq): + p, q = pq + p1, p2, p3 = ints(p) + q1, q2, q3 = ints(q) + return (p, q), sqrt((p1 - q1) ** 2 + (p2 - q2) ** 2 + (p3 - q3) ** 2) + + +if __name__ == "__main__": + with open("./input/08.txt", "r") as f: + inp = f.read().strip() + + p1, p2 = solve(inp) + + print(p1) + print(p2) + + assert p1 == 84968 + assert p2 == 8663467782