Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Making Change by Sim0000
def checkio(price, denominations):
table = [0] + [price + 1] * price
for coin in denominations:
for i in range(coin, price + 1):
table[i] = min(table[i], table[i - coin] + 1)
return table[price] if table[price] <= price else None
# dynamic programming
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')
March 22, 2016
Comments: