diff options
author | Botond Hende <nettingman@gmail.com> | 2024-12-13 20:52:55 +0100 |
---|---|---|
committer | Botond Hende <nettingman@gmail.com> | 2024-12-13 20:52:55 +0100 |
commit | 1ffc2556d4ae91a6a568def1fb79410cf70eb795 (patch) | |
tree | 0c60a0eaa603edfcaf34a6979177a577388bbd50 /2024/day13/solve.py | |
parent | 1d3fff4219458283ce7919c3fb5c94951a66dac7 (diff) |
2024 day 12-13
Diffstat (limited to '2024/day13/solve.py')
-rw-r--r-- | 2024/day13/solve.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/2024/day13/solve.py b/2024/day13/solve.py new file mode 100644 index 0000000..ade85f0 --- /dev/null +++ b/2024/day13/solve.py @@ -0,0 +1,27 @@ +def solve_machine(a_x: int, a_y: int, b_x: int, b_y: int, prize_x: int, prize_y: int) -> int:
+ cheapest_solution = 500
+ for a_press_times in range(101):
+ for b_press_times in range(101):
+ if a_press_times * a_x + b_press_times * b_x == prize_x and a_press_times * a_y + b_press_times * b_y == prize_y and a_press_times * 3 + b_press_times < cheapest_solution:
+ cheapest_solution = a_press_times * 3 + b_press_times
+
+ if cheapest_solution == 500:
+ return 0
+
+ return cheapest_solution
+
+
+with open("input") as f:
+ all_text = f.read()
+
+result = 0
+for details in all_text.split("\n\n"):
+ lines = details.split("\n")
+ button_a = lines[0][10:].split(", ")
+ button_b = lines[1][10:].split(", ")
+ prize = lines[2][7:].split(", ")
+ result += solve_machine(int(button_a[0][2:]), int(button_a[1][2:]),
+ int(button_b[0][2:]), int(button_b[1][2:]),
+ int(prize[0][2:]), int(prize[1][2:]))
+
+print(result)
|