|
@@ -0,0 +1,63 @@
|
|
1
|
+from collections import defaultdict
|
|
2
|
+from itertools import combinations, product
|
|
3
|
+from math import ceil
|
|
4
|
+
|
|
5
|
+weapons = {
|
|
6
|
+ 'dagger': {'cost': 8, 'damage': 4},
|
|
7
|
+ 'shortsword': {'cost': 10, 'damage': 5},
|
|
8
|
+ 'warhammer': {'cost': 25, 'damage': 6},
|
|
9
|
+ 'longsword': {'cost': 40, 'damage': 7},
|
|
10
|
+ 'greataxe': {'cost': 74, 'damage': 8}
|
|
11
|
+}
|
|
12
|
+
|
|
13
|
+armour = {
|
|
14
|
+ 'none': {'cost': 0},
|
|
15
|
+ 'leather': {'cost': 13, 'armour': 1},
|
|
16
|
+ 'chainmail': {'cost': 31, 'armour': 2},
|
|
17
|
+ 'splintmail': {'cost': 53, 'armour': 3},
|
|
18
|
+ 'bandedmail': {'cost': 75, 'armour': 4},
|
|
19
|
+ 'platemail': {'cost': 102, 'armour': 5}
|
|
20
|
+}
|
|
21
|
+
|
|
22
|
+rings = {
|
|
23
|
+ 'none1': {'cost': 0},
|
|
24
|
+ 'none2': {'cost': 0},
|
|
25
|
+ 'damage1': {'cost': 25, 'damage': 1},
|
|
26
|
+ 'damage2': {'cost': 50, 'damage': 2},
|
|
27
|
+ 'damage3': {'cost': 100, 'damage': 3},
|
|
28
|
+ 'defense1': {'cost': 20, 'armour': 1},
|
|
29
|
+ 'defense2': {'cost': 40, 'armour': 2},
|
|
30
|
+ 'defense3': {'cost': 80, 'armour': 3}
|
|
31
|
+}
|
|
32
|
+
|
|
33
|
+boss_stats = {
|
|
34
|
+ 'hp': 104,
|
|
35
|
+ 'damage': 8,
|
|
36
|
+ 'armour': 1
|
|
37
|
+}
|
|
38
|
+
|
|
39
|
+def get_loadouts():
|
|
40
|
+ return product(weapons.values(), armour.values(), combinations(rings.values(), 2))
|
|
41
|
+
|
|
42
|
+def get_stats(loadout):
|
|
43
|
+ weapon, armour, (ring1, ring2) = loadout
|
|
44
|
+ stats = defaultdict(int)
|
|
45
|
+ stats['hp'] = 100
|
|
46
|
+ for part in (weapon, armour, ring1, ring2):
|
|
47
|
+ for k, v in part.items():
|
|
48
|
+ stats[k] += v
|
|
49
|
+ stats['loadout'] = loadout
|
|
50
|
+ return stats
|
|
51
|
+
|
|
52
|
+def will_win(my_stats, boss_stats):
|
|
53
|
+ inflicted_dpt = max(1, my_stats['damage'] - boss_stats['armour'])
|
|
54
|
+ received_dpt = max(1, boss_stats['damage'] - my_stats['armour'])
|
|
55
|
+ boss_death_turn = ceil(boss_stats['hp'] / inflicted_dpt)
|
|
56
|
+ my_death_turn = ceil(my_stats['hp'] / received_dpt)
|
|
57
|
+ return my_death_turn >= boss_death_turn
|
|
58
|
+
|
|
59
|
+stats = (s for s in (get_stats(l) for l in get_loadouts()) if will_win(s, boss_stats))
|
|
60
|
+print(min(stats, key=lambda s: s['cost']))
|
|
61
|
+
|
|
62
|
+stats = (s for s in (get_stats(l) for l in get_loadouts()) if not will_win(s, boss_stats))
|
|
63
|
+print(max(stats, key=lambda s: s['cost']))
|