Given a list of coins and a positive integer n>0 I need to find the number of permutations which sum up to n. Each coin on the list can be used many times. for example - given the following list: lst = [1,3,4] and n=4, the function should return 4: for : [1,1,1,1], [1,3], [3,1] and [4]. I was asked to give a reursive solution. I know how to write a recursive code which counts the number of combinations, but I don't know how to write the code which counts the number of permutations.
This is my code:
def coin_change(lst, n):
if n == 0:
return 1
if len(lst) == 0:
return 0
if n<0:
return 0
return coin_change(lst, n-lst[0]) + coin_change(lst[1:], n)
Thanks