Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Speedy and relatively clear solution in Speedy category for Making Change by Vasily__Chibilyaev
def checkio(price, denomin):
def min_coins(price, denomin, count=0, res=float('inf')):
if price==0:
res=min(res, count)
elif price>0 and len(denomin)>0:
d=denomin[0]
if count+price//d>=res: return res
tmp=denomin[1:]
for i in range(price//d,-1,-1):
p=price-i*d
res=min_coins(p, tmp, count+i, res)
return res
denomin.sort(reverse=True)
res=min_coins(price=price, denomin=denomin)
return res if res
Sept. 21, 2017
Comments: