From 1e807b5daf487ef5434c3491f3334c2f91c85e4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Engl=C3=B6f=20Ytterstr=C3=B6m?= Date: Fri, 13 Dec 2024 15:15:05 +0100 Subject: [PATCH] Solve 2024:13 p1-2 "Claw Contraption" Initial version of the code tried to solve pt 1 using BFS, which took way too long even for the test data. After some fiddling with algebra with pen and paper, I realized this 2 formulaes (using first example): 94 * b1 + 22 * b2 == 840 34 * b1 + 67 * b2 == 540 *b1 = button A presses *b2 = button B presses ... could be rewritten to this single expression: (94 + 34) * b1 + (22 + 67) * b2 = 840 * 540 I failed to remember the algebra for solving x than y though, that I had to learn from the subreddit. In the code, this is the ratio part. Also, this solution using fractions is SICK. https://www.reddit.com/r/adventofcode/comments/1hd4wda/comment/m1tz3nf/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button --- 2024-python/output/day_12.py | 6 ++++-- 2024-python/output/day_13.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 2024-python/output/day_13.py diff --git a/2024-python/output/day_12.py b/2024-python/output/day_12.py index 712e3e1..c476aa0 100644 --- a/2024-python/output/day_12.py +++ b/2024-python/output/day_12.py @@ -25,11 +25,13 @@ def solve(data): areas += 1 y, x = rc for dy, dx in D: - if (0 <= y + dy < H and 0 <= x + dx