A repro for all my Advent of ode tasks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

39 lines
1.3 KiB

import itertools
ingredients = {}
results = []
results_500 = []
file = open('_input.txt', 'r')
for line in file:
splits = line.split(' ')
ingredients.setdefault(splits[0], {'capacity' : int(splits[2].strip(",")), 'durability': int(splits[4].strip(",")), 'flavor': int(splits[6].strip(",")), 'texture' : int(splits[8].strip(",")), 'calories' : int(splits[10].strip(","))})
for perm in itertools.combinations_with_replacement(ingredients, 101):
ingredient_count = {}
for i in range(0, len(perm)-1):
ingredient_count.setdefault(perm[i], 0)
ingredient_count[perm[i]] += 1
#print(ingredient_count)
current_score = 0
capacity = 0
durability = 0
flavor = 0
texture = 0
calories = 0
for k, v in ingredient_count.items():
capacity += (v * ingredients[k]['capacity'])
durability += (v * ingredients[k]['durability'])
flavor += (v * ingredients[k]['flavor'])
texture += (v * ingredients[k]['texture'])
calories += (v * ingredients[k]['calories'])
current_score = max(0, capacity) * max(0, durability) * max(0, flavor) * max(0, texture)
#print(current_score)
results.append([current_score, perm])
if calories == 500:
results_500.append([current_score, perm])
print( max(results) )
print( max(results_500) )