Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
11-liner: get rich solution in Clear category for Treasures by przemyslaw.daniel
def treasures(info, limit):
price_per_gram = sorted(info, key=lambda x: info[x]['price'] / info[x]['weight'])
result, weight = {}, int(1000*limit)
for valuable in reversed(price_per_gram):
amount = min(weight // info[valuable]['weight'], info[valuable]['amount'])
result[valuable] = amount
weight -= amount*info[valuable]['weight']
valuables = 'golden coin,silver coin,ruby'.split(',')
return [f"{valuable}: {result[valuable]}" for valuable in valuables if result[valuable]]
Sept. 18, 2018
Comments: