You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.8 KiB
Python
72 lines
1.8 KiB
Python
import re
|
|
import numpy as np
|
|
|
|
# list of ingredients
|
|
# each line is an ingredient
|
|
# each col is the property
|
|
INGREDIENTS = []
|
|
|
|
with open("input") as f:
|
|
lines = [n.strip() for n in f.readlines()]
|
|
|
|
for line in lines:
|
|
values = re.findall("-?[0-9]+", line)
|
|
values = [int(x) for x in values]
|
|
INGREDIENTS.append(values)
|
|
|
|
NUM_INGREDIENTS = len(INGREDIENTS)
|
|
NUM_PROPERTIES = len(INGREDIENTS[0])
|
|
|
|
# list of properties
|
|
# each line is a property
|
|
# ech col is theingredient
|
|
PROPERTIES = np.zeros((NUM_PROPERTIES, NUM_INGREDIENTS))
|
|
for idx_a, values in enumerate(INGREDIENTS):
|
|
for idx_b, value in enumerate(values):
|
|
PROPERTIES[idx_b][idx_a] = value
|
|
|
|
|
|
print(INGREDIENTS)
|
|
print(PROPERTIES)
|
|
|
|
max_score = 0
|
|
amounts = None
|
|
|
|
for a in range(0, 101):
|
|
print(a)
|
|
for b in range(0, 101 - a):
|
|
for c in range(0, 101 - (a + b)):
|
|
for d in range(0, 101 - (a + b + c)):
|
|
score = 1
|
|
multipliers = [a, b, c, d]
|
|
calorie_sum = sum([a * b for a, b in zip(PROPERTIES[-1], multipliers)])
|
|
if calorie_sum != 500:
|
|
continue
|
|
for prop in PROPERTIES[:-1]:
|
|
prop_sum = sum([a * b for a, b in zip(prop, multipliers)])
|
|
if prop_sum < 0:
|
|
prop_sum = 0
|
|
score *= prop_sum
|
|
|
|
if score > max_score:
|
|
max_score = score
|
|
amounts = [a, b, c, d]
|
|
# print("New leader:", score, amounts)
|
|
|
|
print("finish")
|
|
print(int(max_score))
|
|
print(amounts)
|
|
|
|
multipliers = amounts
|
|
score = 1
|
|
for prop in PROPERTIES:
|
|
prop_sum = sum([a * b for a, b in zip(prop, multipliers)])
|
|
if prop_sum < 0:
|
|
prop_sum = 0
|
|
score *= prop_sum
|
|
print("score", prop_sum)
|
|
|
|
|
|
# 35087450112 too high [0, 0, ?, ?]
|
|
# 6211814400 too high [28, 32, 18, 22]
|