Given $K$ elements between $1$ and $7$ (inclusive), how many ways can you arrange the elements s.t. their sum adds to $N$?
I can brute-force my way to counting the number of ways for small $K$ and $N$, but is there a general formula that addresses this problem? I feel like this is a commonly discussed problem, but I just don't know what the solution is. This came out of something I'm working on (programming stuff). Thanks.
The best way to solve this is via a generating function. We treat the powers of $x$ as the values of $k$
So, to represent the fact that each element can take on any value from 1 to 7, we introduce a polynomial with 1 term for each power between 1 and 7, i.e., $x+x^2+x^3+x^4+x^5+x^6+x^7=\frac{x^8-1}{x-1}$. Then, since there are $k$ elements, we raise this polynomial to the $k$th power, and find the coefficient of $x^n$ in the result.
So, our answer will be the coefficient of $x^n$ in $$\bigg(\frac{x^8-1}{x-1}\bigg)^k$$