Skip to content

Commit 6ccf6a4

Browse files
committed
completed day 21 of year 2015
1 parent 566cd14 commit 6ccf6a4

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

‎2015/21.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
split_data = True
5+
completed = False
6+
raw_data = None # Not To be touched
7+
8+
shop = {
9+
"weapons": [(8, 4), (10, 5), (25, 6), (40, 7), (74, 8)],
10+
"armor": [(0, 0), (13, 1), (31, 2), (53, 3), (75, 4), (102, 5)],
11+
"rings": [(0,0,0), (0,0,0), (25,1,0), (50,2,0), (100,3,0), (20,0,1), (40,0,2), (80,0,3)]
12+
}
13+
14+
def part1(data):
15+
enemy_damage, enemy_armor = int(data[1].split(":")[1]), int(data[2].split(":")[1])
16+
17+
best_cost = float('inf')
18+
19+
for wc, wd in shop['weapons']:
20+
for ac, ad in shop['armor']:
21+
for i, rls in enumerate(shop['rings']):
22+
for rrs in shop['rings'][i+1:]:
23+
cost = wc + ac + rls[0] + rrs[0]
24+
damage = wd + rls[1] + rrs[1]
25+
armor = ad + rls[2] + rrs[2]
26+
27+
# Now we need our effective damage to be higher than the enemies effective damage
28+
if damage - enemy_armor < enemy_damage - armor: continue
29+
30+
best_cost = min(best_cost, cost)
31+
32+
return best_cost
33+
34+
35+
36+
def part2(data):
37+
enemy_damage, enemy_armor = int(data[1].split(":")[1]), int(data[2].split(":")[1])
38+
39+
most_cost = 0
40+
41+
for wc, wd in shop['weapons']:
42+
for ac, ad in shop['armor']:
43+
for i, rls in enumerate(shop['rings']):
44+
for rrs in shop['rings'][i+1:]:
45+
cost = wc + ac + rls[0] + rrs[0]
46+
damage = wd + rls[1] + rrs[1]
47+
armor = ad + rls[2] + rrs[2]
48+
49+
# Now we need our effective damage to be lower than the enemies effective damage
50+
if damage - enemy_armor >= enemy_damage - armor: continue
51+
52+
most_cost = max(most_cost, cost)
53+
54+
return most_cost

0 commit comments

Comments
 (0)