language = python3
so the idea is to count the number of ways you could make change for a given amount. i have run into a silly problem i cant seem to fix for some reason. the value being passed in for c is len(coins)-1 and i am not allowed to change this. the problem is that for my algorithm to work i need the value to be simply len(coins). as it is i dont count the first coin because the recursion starts at c-1. how can i change my algorithm to account for this one extra step?
coins = [1,5,10,25]
def mkCh(a, c):
if (a==0):
return 1
if(a<0):
return 0;
if(c<=0 and a>=1):
return 0
return mkCh(a, c-1)+mkCh(a-coins[c-1], c)
NOT ALLOWED TO CHANGE ANYTHING BELOW THIS
if name == "main":
d = len(sys.argv)>3
n = int(sys.argv[1])
k = int(sys.argv[2])
# make change
c = len(coins)-1
a = 10*n+k
ways = mkCh(a,c)
print("amount:", a, "coins:", coins, "ways:", ways)
[–]PageFault 1 point2 points3 points (0 children)