This is a part of a bigger problem I was solving.
Problem: $N$ is a positive integer. There are $k$ number of other positive integers ($\le N$) In how many ways can you make $N$ by summing up any number of those $k$ integers. You can use any integer, any number of times.
For example: $N = 10$, $k=1: \{ 1 \}$
then there's only $1$ way of making $10$ using integers in braces: $1+1+1+1+\cdots+1 = 10$
another example: $N = 10$, $k = 2: \{ 1, 3\}$
number of ways $= 4$:
$1,1,1,1,1,1,1,1,1,1$
$1,1,1,1,1,1,1,3$
$1,1,1,1,3,3$
$1,3,3,3$
The question is to derive a generalized logic/formula to calculate the number of ways.
subsetPartitions[n_Integer?Positive, vec_List] := Flatten[MapThread[ConstantArray, {vec, #}]] & /@ FrobeniusSolve[vec, n] /; VectorQ[vec, IntegerQ] && Apply[And, Thread[0 < vec <= n]]does the job. TrysubsetPartitions[10, {1, 3}]. – J. M. ain't a mathematician Nov 07 '11 at 04:25IntegerPartitions[10, All, {1, 3}]. – Sasha Nov 07 '11 at 19:10