Created
June 9, 2016 19:58
-
-
Save Apsu/cdbe6a251a1e23391d22e8b8631aa94f to your computer and use it in GitHub Desktop.
SICP Python Conversion
This file contains 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
#!/usr/bin/env python | |
def count_change(amount): | |
return cc(amount, 5) | |
def cc(amount, kinds_of_coins): | |
if(amount == 0): | |
return 1 | |
elif(amount < 0 or kinds_of_coins == 0): | |
return 0 | |
else: | |
return ( | |
cc(amount, kinds_of_coins - 1) + | |
cc(amount - first_denomination(kinds_of_coins), kinds_of_coins) | |
) | |
def first_denomination(kinds_of_coins): | |
if(kinds_of_coins == 1): | |
return 1 | |
elif(kinds_of_coins == 2): | |
return 5 | |
elif(kinds_of_coins == 3): | |
return 10 | |
elif(kinds_of_coins == 4): | |
return 25 | |
elif(kinds_of_coins == 5): | |
return 50 | |
print(count_change(100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment