Skip to content

Commit

Permalink
AoC 2024 day 13 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
loociano committed Dec 14, 2024
1 parent 04af05b commit 0286577
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions aoc2024/src/day13/python/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ def _calc_tokens(vector_0: Vector, vector_1: Vector, vector_2: Vector) -> int |


def min_tokens_to_win(input: Sequence[str], price_offset: int = 0) -> int | None:
def add_price_offset(machine: Machine) -> Machine:
"""Adds a given offset to price position."""
new_price_vector = (machine[2][0] + price_offset, machine[2][1] + price_offset)
return machine[0], machine[1], new_price_vector

claw_machines = _parse(input)
if price_offset > 0:
claw_machines = tuple(map(add_price_offset, claw_machines))
num_tokens = 0
for machine in claw_machines:
tokens = _calc_tokens(machine[0], machine[1], machine[2])
Expand Down
3 changes: 3 additions & 0 deletions aoc2024/test/day13/python/test_solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def test_part1_withExample5_correct(self):
def test_part1_withPuzzleInput_correct(self):
self.assertEqual(32067, min_tokens_to_win(self.input))

def test_part2_withPuzzleInput_correct(self):
self.assertEqual(92871736253789, min_tokens_to_win(self.input, price_offset=10000000000000))


if __name__ == '__main__':
unittest.main()

0 comments on commit 0286577

Please sign in to comment.