Last active
December 28, 2015 15:39
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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