diff --git a/advent/days/day02/solution.py b/advent/days/day02/solution.py index 53c9487..1cfabe0 100644 --- a/advent/days/day02/solution.py +++ b/advent/days/day02/solution.py @@ -11,7 +11,7 @@ def part1(lines: Iterator[str]) -> int: def part2(lines: Iterator[str]) -> int: - return sum(result.score(opponent) + return sum(result.player_shape(opponent).score(opponent) for opponent, result in (Result.parse(line) for line in lines)) @@ -187,9 +187,9 @@ class Result(Enum): case 'Z': return Result.Win case _: raise Exception(f"Unknown char : {char}") - def score(self, other: Shape) -> int: - """ The score we get by the given shape and the expected result """ + def player_shape(self, other: Shape) -> Shape: + """ The shape the player must choose to get the expected result""" match self: - case Result.Lose: return other.prev().score(other) - case Result.Draw: return other.score(other) - case Result.Win: return other.next().score(other) + case Result.Lose: return other.prev() + case Result.Draw: return other + case Result.Win: return other.next() diff --git a/advent/days/day02/test_solution.py b/advent/days/day02/test_solution.py index 68d9cac..e8ff014 100644 --- a/advent/days/day02/test_solution.py +++ b/advent/days/day02/test_solution.py @@ -33,13 +33,13 @@ def test_round1(): def test_round2(): input = "A Y" - expected = 4 - opponent, player = Result.parse(input) - assert player.score(opponent) == expected + expected = Shape.Rock + opponent, result = Result.parse(input) + assert result.player_shape(opponent) == expected def test_round3(): input = "B X" expected = 1 - opponent, player = Result.parse(input) - assert player.score(opponent) == expected + opponent, result = Result.parse(input) + assert result.player_shape(opponent).score(opponent) == expected