diff options
Diffstat (limited to '22')
-rw-r--r-- | 22/solution.py | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/22/solution.py b/22/solution.py index 2859416..6df8379 100644 --- a/22/solution.py +++ b/22/solution.py @@ -1,2 +1,42 @@ +from functools import cache +from collections import namedtuple + +Opponent = namedtuple('Opponent', ['hp', 'damage']) + +def part1(opponent: Opponent) -> int: + @cache + def min_cost(php: int, pmana: int, ohp: int, sld_timer: int, psn_timer: int, rch_timer: int) -> int | float: + psld = 0 + def effects(): + nonlocal ohp, pmana, psld, psn_timer, rch_timer, sld_timer + if sld_timer > 0: + sld_timer -= 1 + psld = 7 + else: + psld = 0 + if psn_timer > 0: + psn_timer -= 1 + ohp -= 3 + if rch_timer > 0: + rch_timer -= 1 + pmana += 101 + + def opponent_turn(cost: int) -> int | float: + effects() + nonlocal php + if ohp <= 0: + return cost + php -= min(1, opponent.attack - psld) + if php <= 0: + return float('inf') + return cost + min_cost(php, pmana, ohp, sld_timer, psn_timer, rch_timer) + + effects() + if ohp <= 0: + return 0 + if __name__ == '__main__': - with open('input') as f:
\ No newline at end of file + opponent = Opponent(51, 9) + + print(part1(opponent)) + #print(part2(opponent)) |