9
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ For a more general problem see: math.stackexchange.com/questions/4643/… $\endgroup$
    – alext87
    Commented Sep 14, 2010 at 13:10
  • $\begingroup$ I imagine this can be done with generating functions (but I can't be bothered to actually do it, sorry). $\endgroup$ Commented Sep 14, 2010 at 13:49
  • $\begingroup$ @Oscar: I just noticed your comment! See my answer. $\endgroup$
    – Aryabhata
    Commented Sep 14, 2010 at 14:16

3 Answers 3

12
$\begingroup$

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}$$

$\endgroup$
6
  • $\begingroup$ Beat me to it! There's a slight typo, 1/(1-x)^n = sum C(k+n-1,k) x^k (off by one). $\endgroup$ Commented Sep 14, 2010 at 14:20
  • $\begingroup$ Shouldn't the first expression be (x+x^2+x^3...x^m)^n [i.e. without the one on the front]? Otherwise you're saying that an m-sided dice can take any of the m+1 values from 0 to m. $\endgroup$ Commented Sep 14, 2010 at 14:47
  • $\begingroup$ @OScar: You are right. I will edit the answer. $\endgroup$
    – Aryabhata
    Commented Sep 14, 2010 at 15:04
  • $\begingroup$ Amusingly, the example that Yuval worked out below came to be correct anyway, since you need to use all your dice to roll a 7 with two dice. $\endgroup$ Commented Sep 14, 2010 at 15:07
  • 3
    $\begingroup$ Fun fact in this context: en.wikipedia.org/wiki/Sicherman_dice $\endgroup$ Commented Sep 14, 2010 at 18:17
2
$\begingroup$

The formula in the last answer (of Yuval Filmus) seems to be wrong: for m=4,n=9,S=6 one gets a nonzero result while it's impossible to have a sum of 6 with 9 dices!

The wanted formula i guess is the one corresponding to the coefficient "c" at http://mathworld.wolfram.com/Dice.html

$\endgroup$
1
  • $\begingroup$ Yuval's dice take values from 0 to m, not from 1 to m. Granted, these are not standard dice! $\endgroup$
    – user940
    Commented Aug 12, 2015 at 22:04
1
$\begingroup$

Continuing Moron's answer, you can break the final sum as follows:

$$ \sum_{r=0}^{\lfloor S/(m+1) \rfloor} (-1)^r \binom{n-1+S-r(m+1)}{n-1} \binom{n}{r} $$

For example, for your example, $m=6$, $n=2$, $S=7$, and the formula gives

$$ \binom{8}{1} \binom{2}{0} - \binom{1}{1} \binom{2}{1} = 8 - 2 = 6 $$

$\endgroup$
2
  • $\begingroup$ Can you just show the calculation for m=6, n =2, and S=3 for this formula? $\endgroup$
    – Manoj R
    Commented Feb 21, 2011 at 10:34
  • $\begingroup$ Then there is only one term in the sum, $\binom{4}{1} \binom{2}{0} = 4$, which probably corresponds to $(1,2),(2,1),(4,),(,4)$. See Oscar's comment to Moron's answer. This problem can be fixed. $\endgroup$ Commented Feb 21, 2011 at 15:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .