# Deriving a closed form for rolling a sum $n$ with $k$ dice using stars and bars [closed]

I am trying to derive a closed form for computing the number possible outcomes of rolling $k$ dices such that the sum is $n$.

This seems to be the problem of finding number of positive integral solution of an equation $$x_1+x_2+\cdots+x_k=n$$ with $x_1,x_2,\cdots,x_n \in [1,6]$,but here a solution $(a,a,a,a,\cdots \text { k-times} )$ is not considered different.

Direct application of stars and bars gives a closed form $\binom{n-1}{2} \times k \binom{n-7}{2}$ but this is not working for all the cases, For example the case of $n=16$ and $k=3$,what exactly should I modify in my approach?

-

## closed as off topic by Qiaochu Yuan, Todd Trimble♦, Gerry Myerson, Kevin Walker, S. Carnahan♦Oct 25 '11 at 9:02

Questions on MathOverflow are expected to relate to research level mathematics within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.

A much better fit for m.se. –  Gerry Myerson Oct 24 '11 at 21:19
The definition of "different" is incomprehensible. Difference is a binary relation. State precisely when two dice roles are considered the same. –  Brendan McKay Oct 25 '11 at 0:43
One problem with directing this question to Math.StackExchange is that it has been asked there before but most of the answers have been wrong or misleading. –  Douglas Zare Oct 25 '11 at 8:49
@Douglas Zare:That is the reason I posted it here,I see it is closed now,but I guess I got my answer :) –  user18748 Oct 25 '11 at 13:46

Answer is given by the coefficient of $z^n$ in $$(z+z^2+\dots+z^6)^k = \left(z\frac{1-z^6}{1-z}\right)^k = z^k (1-z^6)^k(1-z)^{-k}.$$ An explicit formula for this coefficient is: $$\sum_{i=0}^{\min(k,\lfloor (n-k)/6\rfloor)} (-1)^{n+i} \binom{k}{i} \binom{-k}{n-k-6i} = \sum_{i=0}^{\min(k,\lfloor (n-k)/6\rfloor)} (-1)^i \binom{k}{i} \binom{n-6i-1}{k-1}.$$