diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-11-26 23:51:59 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-11-26 23:51:59 +0000 |
commit | deb9cd82db7f5b6a44f613feb0959110ce70c2e6 (patch) | |
tree | de0038e31cb65a8106fe30f4effdbcf883759683 /22 | |
parent | 0e8e49af605d3160645e773fdec53b7cf60cc068 (diff) | |
download | aoc2015-deb9cd82db7f5b6a44f613feb0959110ce70c2e6.tar.gz aoc2015-deb9cd82db7f5b6a44f613feb0959110ce70c2e6.tar.xz aoc2015-deb9cd82db7f5b6a44f613feb0959110ce70c2e6.zip |
solutions
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)) |