Generate (in R) a matrix of all possible outcomes for throwing n dice (ignoring order)
Posted
by Brani
on Stack Overflow
See other posts from Stack Overflow
or by Brani
Published on 2010-05-23T19:09:27Z
Indexed on
2010/05/23
19:10 UTC
Read the original article
Hit count: 219
In cases where order does matter, it's rather easy to generate the matrix of all possible outcomes. One way for doing this is using expand.grid
as shown here.
What if it doesn't?
If I'm right, the number of possible combinations is (S+N-1)!/S!(N-1)!
, where S is the number of dice, each with N sides numbered 1 through N. (It is different from the well known combinations formula because it is possible for the same number to appear on more than one dice). For example, when throwing four six-sided dice, N=6 and S=4, so the number of possible combinations is (4+6-1)!/4!(6-1)! = 9!/4!x5! = 126. How can I generate a matrix of these 126 possible outcomes?
Thank you.
© Stack Overflow or respective owner