-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday21p1.py
More file actions
executable file
·67 lines (52 loc) · 1.49 KB
/
day21p1.py
File metadata and controls
executable file
·67 lines (52 loc) · 1.49 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
from copy import copy
from itertools import izip
from math import ceil
def tuple_add(tuple1, tuple2):
return tuple(x + y for x, y in izip(tuple1, tuple2))
def hits_to_kill(attacker, defender):
rel_damage = attacker['damage'] - defender['armor']
if rel_damage < 1:
rel_damage = 1
return ceil(defender['hitpoints'] / float(rel_damage))
# tuple is (Cost, Damage, Armor)
weapons = [
(8, 4, 0), (10, 5, 0), (25, 6, 0), (40, 7, 0), (74, 8, 0),
]
armor = [
(0, 0, 0), (13, 0, 1), (31, 0, 2), (53, 0, 3), (75, 0, 4), (102, 0, 5),
]
rings = [
(25, 1, 0), (50, 2, 0), (100, 3, 0), (20, 0, 1), (40, 0, 2), (80, 0, 3),
]
rings_comb = [(0, 0, 0)] + rings
for idx in xrange(len(rings) - 1):
for idx2 in xrange(idx + 1, len(rings)):
rings_comb.append(tuple_add(rings[idx], rings[idx2]))
full_combs = list()
for weapon in weapons:
for arm in armor:
for ring in rings_comb:
full_combs.append(
tuple_add(tuple_add(weapon, arm), ring)
)
# Yeah, not reading this in from data file...
boss = {
'hitpoints': 103,
'damage': 9,
'armor': 2,
}
myself = {
'hitpoints': 100,
'damage': 0,
'armor': 0,
}
min_cost = 100000
for comb in full_combs:
new_myself = copy(myself)
new_myself['damage'] += comb[1]
new_myself['armor'] += comb[2]
if hits_to_kill(new_myself, boss) <= hits_to_kill(boss, new_myself):
if comb[0] < min_cost:
min_cost = comb[0]
print min_cost