Consider the array `[3,6,9,12]`. If we generate all the combinations with repetition that sum to `12`, we get `5` combinations: `[12], [6,6], [3,9], [3,3,6], [3,3,3,3]`. The length of the sub-arrays (such as `[3,3,3,3]` should be less than or equal to the length of the initial array (`[3,6,9,12]`).  

Given an array of positive integers and a number `n`, count all combinations with repetition of integers that sum to `n`. For example: 
```Haskell
find([3,6,9,12],12) = 5.
```

More examples in the test cases. 

Good luck!

If you like this Kata, please try:

[Array combinations](https://www.codewars.com/kata/59e66e48fc3c499ec5000103)

[Sum of prime-indexed elements](https://www.codewars.com/kata/59f38b033640ce9fc700015b)

Difficulty: introductory

Starter code:

def find(arr,n):
	

Solutions:
from itertools import combinations_with_replacement

def find(arr,n):
    return sum( sum(c) == n for x in range(1,len(arr)+1) for c in combinations_with_replacement(arr, x) )

def find(arr,n):
    return(findl(arr,n,len(arr)))
def findl(arr,n,l):
    return(sum(findl(arr[1:],n-arr[0]*i,l-i) for i in range(l+1)) if ((arr) and (l>0)) else ((n==0) and (l>=0)))

import itertools


#Given the lst of length N, we generate a list of all possible combinations with
#  replacements from choose-1 to choose-N
#Then, for each of the combinations found, simply sum the contents and see if the sum
#matches the target sum
# Example [3, 6, 9, 12] with target sum 12. Here we need a total of 4; 
# choose (with replacement) 1 from 4, 2 from 4, 3 from 4, 4 from 4
# Choose 1 [(3,), (6,), (9,), (12,)]
# Choose 2 [(3, 3), (3, 6), (3, 9), (3, 12), (6, 6), (6, 9), (6, 12), (9, 9), (9, 12), (12, 12)]
#           [(3, 3, 3), (3, 3, 6), (3, 3, 9), (3, 3, 12), (3, 6, 6), (3, 6, 9), (3, 6, 12), (3, 9, 9),
#            (3, 9, 12), (3, 12, 12), (6, 6, 6), (6, 6, 9), (6, 6, 12), (6, 9, 9), (6, 9, 12), 
#            (6, 12, 12), (9, 9, 9), (9, 9, 12), (9, 12, 12), (12, 12, 12)]
# Choose 3 [(3, 3, 3, 3), (3, 3, 3, 6), (3, 3, 3, 9), (3, 3, 3, 12), (3, 3, 6, 6), (3, 3, 6, 9),
#           (3, 3, 6, 12), (3, 3, 9, 9), (3, 3, 9, 12), (3, 3, 12, 12), (3, 6, 6, 6), (3, 6, 6, 9),
#           (3, 6, 6, 12), (3, 6, 9, 9), (3, 6, 9, 12), (3, 6, 12, 12), (3, 9, 9, 9), (3, 9, 9, 12),
#           (3, 9,12, 12), (3, 12, 12, 12), (6, 6, 6, 6), (6, 6, 6, 9), (6, 6, 6, 12), (6, 6, 9, 9),
#           (6, 6, 9, 12), (6, 6, 12, 12), (6, 9, 9, 9), (6, 9, 9, 12), (6, 9, 12, 12), (6, 12, 12, 12),
#           (9, 9, 9, 9), (9, 9, 9, 12), (9, 9, 12, 12), (9, 12, 12, 12), (12, 12, 12, 12)] 
#Now for each we see which sum to the target of 12
def find(lst, targetSum):
    lenList = len(lst)
    

    combWithReplacementList= []
    for chooseR in range(1, lenList+1):
        combsChooseR = itertools.combinations_with_replacement(lst, chooseR)
        combWithReplacementList.append(list(combsChooseR))

    totalFound = 0
    for col in combWithReplacementList:
        for combChoice in col:
            if (sum(combChoice))== targetSum:
                totalFound +=1

    return totalFound
#----end function


from itertools import combinations_with_replacement as comb

# Brute force!
def find(arr, n):
    return sum(sum(L) == n for i in range(1, len(arr)+1) for L in comb(arr, i))

from itertools import combinations_with_replacement as comb

def find(lst, n):
    return sum(1 for l in range(1, len(lst)+1) for c in comb(lst, l) if sum(c) == n)

from itertools import combinations_with_replacement as c

def find(arr, n):
    return sum(
        sum(xs) == n
        for i in range(len(arr))
        for xs in c(arr, i + 1)
    )

from itertools import combinations_with_replacement as c
find=lambda a,k:sum(1for i in range(1,len(a)+1)for j in c(a,i)if sum(j)==k)

from itertools import combinations_with_replacement as cr
find=lambda a,n:sum(n==sum(c)for r in range(1,len(a)+1)for c in cr(a,r=r))

def N(Q,S,R,L,D,C,I) :
    if 0 < D and 0 < S :
        for I in range(I,L) :
            N(Q,S - Q[I],R,L,D - 1,C + (Q[I],),I)
    elif 0 == S :
        R.add(C)
    return R

def find (Q,S) :
    Q = sorted(set(Q))
    return len(N(Q,S,set(),len(Q),len(Q),(),0))

from itertools import combinations_with_replacement as comb
def find(arr,n):
    return sum(sum(c)==n for i in range(1,len(arr)+1) for c in comb(arr,i))