-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21.py
54 lines (39 loc) · 1.48 KB
/
21.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from lib import *
input = read_input(2015, 21)
(*_, boss_hp), (*_, boss_damage), (*_, boss_armor) = map(str.split, input.splitlines())
boss_hp, boss_damage, boss_armor = map(int, [boss_hp, boss_damage, boss_armor])
player_hp = 100
NEUTRAL = (0, 0, 0)
shop_weapons = [(8, 4, 0), (10, 5, 0), (25, 6, 0), (40, 7, 0), (74, 8, 0)]
shop_armor = [NEUTRAL, (13, 0, 1), (31, 0, 2), (53, 0, 3), (75, 0, 4), (102, 0, 5)]
shop_rings = [NEUTRAL, NEUTRAL, (25, 1, 0), (50, 2, 0), (100, 3, 0), (20, 0, 1), (40, 0, 2), (80, 0, 3)]
def fight(player_damage, player_armor):
player = player_hp
boss = boss_hp
while True:
boss -= max(1, player_damage - boss_armor)
if boss <= 0:
return True
player -= max(1, boss_damage - player_armor)
if player <= 0:
return False
def combine(*args):
return tuple(map(sum, zip(*args)))
best = 1e1337
for weapon in shop_weapons:
for armor in shop_armor:
for i, ring1 in enumerate(shop_rings):
for ring2 in shop_rings[i + 1 :]:
cost, d, a = combine(weapon, armor, ring1, ring2)
if fight(d, a):
best = min(best, cost)
print(best)
best = 0
for weapon in shop_weapons:
for armor in shop_armor:
for i, ring1 in enumerate(shop_rings):
for ring2 in shop_rings[i + 1 :]:
cost, d, a = combine(weapon, armor, ring1, ring2)
if not fight(d, a):
best = max(best, cost)
print(best)