-- CodingAP's Advent of Code Hub --

[Back to Hub]

Advent of Code 2024, Day 13

-- Claw Contraption --

Leaderboard Positions - Part 1: 2316, Part 2: 679

Video Replay

Hello all! In this puzzle, we are trying to figure out the exact number of button presses to reach a goal in a crane machine. Each crane has two buttons labeled A and B, which both buttons advancing the crane arm a specific amount. We need to find how many of each button press will lead to the position being exactly the goal. In part 1, we try to find the amount, then add all the successful A and B numbers with this formula: 3 * A + B. To prevent bruteforcing, we treat each button as a system of linear equations, which we can solve as there are two variables and two equation. I made a Desmos that calculates the A and B given the constants. To map the constant for completion sake:

c1: button a x
c2: button b x
c3: prize x
c4: button a y
c5: button b y
c6: prize y

For part 2, we need to add 10000000000000 to each of the prize positions, which with our current solution shouldn't be a problem. One thing to note is make sure to keep floating point inaccuracies down, so do as much integer arithetic as possible