-
Notifications
You must be signed in to change notification settings - Fork 0
/
15.advent.py
67 lines (53 loc) · 1.68 KB
/
15.advent.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
55
56
57
58
59
60
61
62
63
64
65
66
from inputs import FIFTEENTH
import operator
import functools
ing_attribs = FIFTEENTH.ingredients
class cookie_mix:
ingredients = {}
metrics = [
'capacity',
'durability',
'flavor',
'texture',
'calories',
]
def __init__(self,combo):
self.ingredients['Sugar'] = combo[0]
self.ingredients['Sprinkles'] = combo[1]
self.ingredients['Candy'] = combo[2]
self.ingredients['Chocolate'] = combo[3]
def inc_dec(self, increase, decrease):
self.ingredients[increase] += 1
self.ingredients[decrease] -= 1
return self
def id(self):
return ":".join([str(i) for i in self.ingredients.values()])
def get_score(self):
scores = {
'capacity': 0,
'durability': 0,
'flavor': 0,
'texture': 0,
'calories': 0
}
for metric in self.metrics:
for (ing,amount) in self.ingredients.items():
scores[metric] += ing_attribs[ing][metric] * amount
if True in [s <= 0 for s in scores.values()]:
return 0
if scores['calories'] != 500:
return 0
total_score = functools.reduce(operator.mul,[v for (k,v) in scores.items() if k != 'calories'],1)
print scores, total_score
return total_score
best_score = 0
for i in range(0,100):
for j in range(0,100-i):
for k in range(0,100-i-j):
h = 100-i-j-k
mix = cookie_mix([i,j,k,h])
score = mix.get_score()
if score > best_score:
best_score = score
print 'new best {}'.format(best_score)
print best_score