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)

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

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

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


from itertools import combinations_with_replacement as comb

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((1 for 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))