Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Last active December 28, 2015 15:39
Show Gist options
  • Save animatedlew/7522962 to your computer and use it in GitHub Desktop.
Save animatedlew/7522962 to your computer and use it in GitHub Desktop.
Finding how many combinations of change can be produced based on a total amount and list of denominations in Python.
def count_change(money, coins):
if money == 0:
return 1
if not coins or money < 0:
return 0
else:
return count_change(money-coins[0], coins) + count_change(money, coins[1:])
money = 300
coins = [5, 10, 20, 50, 100, 200, 500]
# 1022
print count_change(money, coins)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment