Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Treasures by fed.kz
def treasures(jewelry, volume):
volume = int(volume*1000)
total = 0
result = {'golden coin': 0, 'silver coin': 0, 'ruby': 0}
while total < volume:
if not any(jewelry[x]['amount'] for x in jewelry): break
best = max(jewelry, key = lambda x: jewelry[x]['amount'] and jewelry[x]['price']/jewelry[x]['weight'])
if jewelry[best]['weight'] <= volume - total:
count = min(jewelry[best]['amount'], (volume - total) // jewelry[best]['weight'])
result[best] += count
total += count * jewelry[best]['weight']
jewelry[best]['amount'] -= count
else:
jewelry[best]['amount'] = 0
return [f'{x}: {result[x]}' for x in result if result[x]]
Sept. 17, 2018
Comments: