Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Treasures by Tinus_Trotyl
def treasures(info, limit):
free, packed, order = limit * 1000, {}, ['golden coin', 'silver coin', 'ruby']
index = {info[cont]['price'] / info[cont]['weight']:cont for cont in info}
ppgs = sorted(list(index))[::-1]
for ppg in ppgs:
pack = min(info[index[ppg]]['amount'], free//info[index[ppg]]['weight'])
free -= pack * info[index[ppg]]['weight']
if pack: packed[index[ppg]] = pack
return[item + ': ' + str(int(packed[item])) for item in order if item in packed]
Sept. 17, 2018
Comments: