Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Making Change by kostya241
def checkio(price, denominations):
pr = [0]+[price+1]*price
for c in denominations:
for p in range(price-c+1):
pr[p+c] = min(pr[p]+1, pr[p+c])
return pr[-1] if pr[-1] != price+1 else None
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(8, [1, 3, 5]) == 2
assert checkio(12, [1, 4, 5]) == 3
print('Done')
Aug. 15, 2017