Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Price weight ratio solution in Clear category for Treasures by pon.tu.correo.aca
def treasures(info, limit):
"""orders the different type of treasures by its price/weight ratio
then adds as much as posible of each one in that order
"""
objects = ['golden coin', 'silver coin', 'ruby']
limit *= 1000
bag ={}
for object in sorted(info, key = lambda key: info[key]['price']/info[key]['weight'], reverse = True):
if limit >= info[object]['amount'] * info[object]['weight']:bag[object] = info[object]['amount']
else:bag[object] = int(limit // info[object]['weight'])
limit -= info[object]['weight'] * bag[object]
return [f"{object}: {bag[object]}" for object in objects if bag[object] > 0]
Sept. 19, 2018
Comments: