Saturday, 11 January 2014

probability - How can I (algorithmically) count the number of ways n m-sided dice can add up to a given number?



I am trying to identify the general case algorithm for counting the different ways dice can add to a given number. For instance, there are six ways to roll a seven with two 6-dice.



I've spent quite a bit of time working on this (for a while my friend and I were using Figurate numbers, as the early items in the series match up) but at this point I'm tired and stumped, and would love some assistance.



So far we've got something to this effect (apologies for the feeble attempt at mathematical notation - I usually reside on StackOverflow):




count(x):
x = min(x,n*m-x+n)
if x = n
1
else
some sort of (recursive?) operation


The first line simplifies the problem to just the lower numbers - where the count is increasing. Then, if we're looking for the count of the minimum possible (which is also now the max because of the previous line) there is only one way to do that so it is 1, no matter the n or m.



Answer



Since the order matters i.e 2+3+4 is different from 3+4+2, you can use generating functions.



The number of ways to get a sum $S$ by rolling $n$ dice (with numbers $1,2,\dots,m$) is the coefficient of $x^S$ in



$$ (x+x^2+\dots+x^m)^n = x^n(\frac{1-x^{m}}{1-x})^n$$



= $$ x^n(1-x^{m})^{n}(\sum_{k=0}^{\infty} {n+k-1 \choose k} x^k)$$



Thus the number of ways is




$$ \sum_{rm+k=S-n} {n \choose r} {n+k-1 \choose k} (-1)^{r}$$


No comments:

Post a Comment

real analysis - How to find $lim_{hrightarrow 0}frac{sin(ha)}{h}$

How to find $\lim_{h\rightarrow 0}\frac{\sin(ha)}{h}$ without lhopital rule? I know when I use lhopital I easy get $$ \lim_{h\rightarrow 0}...