How many ways can the average of n dice be a?

For example, if $n = 2$, and $s=7$ one could have $(1,6), (2,5), (3,3), (4,3), (5, 2), (6,1)$, for six ways.

If $n = 10$ and $s = 30$, one possible combination could be $(1, 2, 3, 4, 3, 2, 1, 5, 6, 3)$.


Solution 1:

The "easy" way of solving problems like this is with generating functions. If you're unfamiliar with them, there's a great introduction by Herb Wilf that shows a lot of their versatility and applicability. Honestly, it's one of the greatest books of all time.

In your problem, let's say you roll $n$ dice and want their sum to be $s$. Then, the generating-function way to represent a roll is the polynomial $r(x)=x+x^2+x^3+x^4+x^5+x^6$. Each of the six terms has a coefficient of 1, meaning that with a single die there is exactly one way to roll each value from one to six. Then, the way to represent a series of $n$ rolls is with a product of $n$ factors of $r(x)$--- in the sense that, for any sum $s$, the coefficient of $x^s$ in the polynomial $(r(x))^n$ is the number of ways to roll $n$ dice with a sum of $s$. By the elegance of generating functions, your entire problem is now reduced to finding the coefficient of a polynomial.

Granted, finding this coefficient takes some work. Notation-wise, let $[x^a]f(x)$ denote the coefficient of $x^a$ in the polynomial or Taylor series $f(x)$. You're interested in $[x^s]r^n(x)$. The polynomial $r(x)$ can be factored as $\frac{x(1-x^6)}{1-x}$. The $n$ factors of $x$ can be removed to get $[x^s]r^n(x)=[x^{s-n}]\frac{1-x^6}{1-x}$. Now the usual rule for multiplying polynomials applies to generating functions, as well: $$[x^a]f(x)\cdot g(x)=\sum_i [x^i]f(x)\cdot[x^{a-i}]g(x).$$ So, with this multiplication rule we have $$[x^{s-n}]\left(\frac{1-x^6}{1-x}\right)^n=\sum_i[x^{6i}](1-x^6)^n\cdot [x^{s-n-6i}]\frac1{(1-x)^n}.$$ By the binomial theorem we have $[x^a](1-x)^b=(-1)^a\binom ba$, and by differentiating a geometric series we have $[x^a]\frac1{(1-x)^{b+1}}=\binom{a+b}a$. Putting these together, we get the number of ways to get a sum of $s$ with $n$ rolls as $$\sum_i(-1)^i\binom ni\binom {s-1-6i}{n-1}.$$

That should shed some light on the answer that Mike Earnest posted above. Numerically, Maple got $4,\!395,\!456$ ways to get a sum of 35 with ten dice.

Solution 2:

The general formula is this: $$ P(\text{sum of all dice }=k)=\sum_{i=0}^{\lfloor k/d\rfloor}(-1)^i\binom{n}{i}\binom{k-6i-1}{n-1} $$ or $$ P(\text{average of all dice }=a)=\sum_{i=0}^{\lfloor k/d\rfloor}(-1)^i\binom{n}{i}\binom{na-6i-1}{n-1} $$ Counting the number of ways to have the sum of $n$ dice equal $k$ is equivalent to counting the number of solutions to this integer equation:

\begin{align} x_1+x_2+\dots+x_n &= k\\ 1\le x_i&\le 6\hspace{2cm} \text{ for }i=1,2,\dots,n \end{align} Let us first count solutions without the contraint $x_i\le 6$. The number of positive integer sequences $(x_1,\dots,x_n)$ which sum to $s$ is $\binom{k-1}{n-1}$. To see this, imagine a line of $k$ dots, with $k-1$ spaces between the dots. Choose $n-1$ of those spaces, and put a divider in the chosen spaces. These dividers break the blocks into $n$ contiguous groups, corresponding to the values of the $n$ variables $x_1,\dots,x_n$.

Now, subtract the bad solutions where some variable $x_i$ is $\ge 7$. If we take such a bad variable and subtract six, we get an integer list summing to $k-6$, so there are $\binom{k-1-6}{n-1}$ such bad solutions. We must subtract this quantity for each variable, so we subtract $n\binom{k-1-6}{n-1}$.

However, solutions with two bad variables have been doubly subtracted, so we must add these back in. To account for overlaps, you use the principle of inclusion exclusion. When counting solutions where a particular set of $i$ variables are bad, subtracting $6$ from each of these variables leaves a list summing to $k-6i$, the number of which is $\binom{k-6i-1}{n-1}$. This leads to the claimed formula.

Solution 3:

To avoid having to use the infinite symbol in the sum, the probability to have a sum of all dice equal to $k$ when rolling $n$ dice can also be written as: $$P\left( {n,k} \right) =\frac{1}{{{6^n}}} \cdot \sum\limits_{i = 0}^{{i_{\max }}} {{{\left( { - 1} \right)}^i}\left( {\begin{array}{*{20}{c}} n\\ i \end{array}} \right)\left( {\begin{array}{*{20}{c}} {k - 6i - 1}\\ {k - 6i - n} \end{array}} \right)}$$ where $\displaystyle {i_{\max }} = \left[ {\frac{{k - n}}{6}} \right]$ and $\left[ x \right]$ represents the "floor" function. For instance, the probability to have a sum $k=31$ when rolling $n=10$ dice is: $$P\left( {10,31} \right) = \frac{1}{{{6^{10}}}} \cdot \sum\limits_{i = 0}^3 {{{\left( { - 1} \right)}^i}\left( {\begin{array}{*{20}{c}} {10}\\ i \end{array}} \right)\left( {\begin{array}{*{20}{c}} {31 - 6i - 1}\\ {31 - 6i - 10} \end{array}} \right)} =$$ $$ \frac{1}{{{6^{10}}}} \cdot \left[ {\left( {\begin{array}{*{20}{c}} {30}\\ {21} \end{array}} \right) - \left( {\begin{array}{*{20}{c}} {10}\\ 1 \end{array}} \right)\left( {\begin{array}{*{20}{c}} {24}\\ {15} \end{array}} \right) + \left( {\begin{array}{*{20}{c}} {10}\\ 2 \end{array}} \right)\left( {\begin{array}{*{20}{c}} {18}\\ 9 \end{array}} \right) - \left( {\begin{array}{*{20}{c}} {10}\\ 3 \end{array}} \right)\left( {\begin{array}{*{20}{c}} {12}\\ 3 \end{array}} \right)} \right] =$$ $$\frac{{3393610}}{{60466176}} = 5.612\% $$ I tried to explain "step-by-step" the inner workings of that formula , using pure combinatorics arguments in my site, at this link, previously cited by Mike Earnest and this proved to be not an easy task.

Mike's comment about that page was not positive but I must admit he was right about the (previous) explanation not being very clear.

So I've recently completely rewritten the page at lucamoroni.it, trying to improve it.

Certainly the answer by Rus May and the content of this article by mathworld are a much more simple and easy way to justify the formula, but they are mainly based on algebraic methods and I looked for another kind of insight.