I have a set of number, and I want to know in how many ways from that set with each number being used zero, once or more times can a certain sum if at all, be achieved. The order doesn't matter. For example, I have a sum of '10' and set of [1,2] and I want to know in how many ways can 1 and 2 be added up to reach 10. Yes, '1' and '2' have to be used more than once.
Example
10 = 1 + 1 + 2 + 2 + 2 + 2
10 = 1 + 1 + 1 + 1 + 2 + 2 + 2
10 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
...
There are more possibilities for the example sum. I don't need the way in which the sum is reached i.e (10 = 1 + 1 + 2 + 2 + 2 + 2 or 10 = 1 + 1 + 2 + 2 + 2 + 2 ...) just how many combinations of '1' and '2' give me 10. I am working with larger sets and numbers, so simple approach will be very useful. Thank-you
No the order does not matter for the sum. Whether it is 10 = 2*one + 4*two or 4*two + 2*one or any other permutation of them. The attempt I made involves the use of a computer. I was thinking about something like this.
for (i = 0; i < sum/i; i++):
for (j = 0; j<sum/j; j++):
if (num1*i + num2*j == sum):
numberOfWays +=1
But this is not useful for larger sets as several nested for loops will be cumbersome. I am looking for an elegant solution.
UPDATE A number can be used 0 times.