Skip to content

Instantly share code, notes, and snippets.

@neale
Last active August 29, 2015 14:20
Show Gist options
  • Save neale/c68e5b7e7ff86be81085 to your computer and use it in GitHub Desktop.
Save neale/c68e5b7e7ff86be81085 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
def changeslow(coins, amounts, highest, sum_coins, goal, store):
if sum_coins == goal:
store == show(coins, amounts, store)
return
if sum_coins > goal:
return
for value in amounts:
if value >= highest:
copy = coins[:]
copy.append(value)
change(copy, amounts, value, sum_coins + value, goal, store)
sum_store = reduce((lambda x, y: x+y), min(store))
return (min(store), sum_store)
def show(coins, amounts, store):
temp = []
for amount in amounts:
count = coins.count(amount)
temp.append(count)
store.append(temp)
return store
coins = []
amounts = [1, 5, 10, 25, 50]
store = []
print changeslow(coins, amounts, 0, 0, 10, store)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment