Last active
December 27, 2015 08:19
-
-
Save phsteve/7295327 to your computer and use it in GitHub Desktop.
My recursive change counting algorithm.
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
#n is the total amount, L is the list of change denominations. | |
def change(n, L): | |
if n < 0: | |
return 0 | |
if n == 0: | |
return 1 | |
if L == []: | |
return 0 | |
return change(n, L[:-1]) + change(n-L[-1], L) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment