Skip to content

Instantly share code, notes, and snippets.

@peregrinogris
Last active December 18, 2015 11:39
Show Gist options
  • Save peregrinogris/5776805 to your computer and use it in GitHub Desktop.
Save peregrinogris/5776805 to your computer and use it in GitHub Desktop.
count coins
def countComb(coins, change, solutions, current):
ret = 0
if sum(current) < change:
for coin in coins:
newComb = [c for c in current]
newComb.append(coin)
ret += countComb(coins, change, solutions, newComb)
if sum(current) == change:
current.sort()
if current not in solutions:
solutions.append(current)
ret = 1
return ret
print countComb([1, 2], 4, [], [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment