Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Brute-force solution solution in Clear category for Treasures by tokyoamado
from itertools import product
def treasures(info, limit):
items, prices, weights, amounts = zip(
*[(c[0], c[1]['price'], c[1]['weight'], c[1]['amount']) for c in info.items()])
amount = max(
(
amount for amount
in product(*map(lambda x: range(x + 1), amounts))
if sum(map(lambda x, y: x * y, weights, amount)) <= limit * 1000
),
key=lambda amount: sum(map(lambda x, y: x * y, prices, amount))
)
results = dict(c for c in zip(items, amount) if c[1])
ret = []
if 'golden coin' in results:
ret.append('golden coin: {}'.format(results['golden coin']))
if 'silver coin' in results:
ret.append('silver coin: {}'.format(results['silver coin']))
if 'ruby' in results:
ret.append('ruby: {}'.format(results['ruby']))
return ret
March 5, 2019
Comments: