Poll

6 votes (54.54%)
1 vote (9.09%)
1 vote (9.09%)
3 votes (27.27%)

11 members have voted

Wizard
Administrator
Wizard
  • Threads: 1520
  • Posts: 27118
Joined: Oct 14, 2009
November 18th, 2015 at 5:26:11 PM permalink
A while ago it was asked what is the expected number of rolls with two dice to achieve every total from 2 to 12. I just created an Expected Trials Calculator to answer such questions. Just put in the probability or number of combinations for up to 19 different outcomes (as many as JavaScript would take), click the calculate button, and viola -- your answer.

Please check it out. As always I welcome questions, comments, and especially corrections.

The question for the poll is what do you think?
"For with much wisdom comes much sorrow." -- Ecclesiastes 1:18 (NIV)
Dalex64
Dalex64
  • Threads: 1
  • Posts: 1067
Joined: Feb 10, 2013
November 18th, 2015 at 6:54:09 PM permalink
I put in ten 2's and a 1
You know, for the number of ways for at least one of the dice to be a certain number.

The answer was 36, which I think makes sense, you might expect to have to cycle through all 36 possibilities to see each of those 11 possibilities once.
Wizard
Administrator
Wizard
  • Threads: 1520
  • Posts: 27118
Joined: Oct 14, 2009
November 18th, 2015 at 8:55:26 PM permalink
Quote: Dalex64

I put in ten 2's and a 1
You know, for the number of ways for at least one of the dice to be a certain number.

The answer was 36, which I think makes sense, you might expect to have to cycle through all 36 possibilities to see each of those 11 possibilities once.



It isn't that there are 36 possibilities. There are an infinite number.
"For with much wisdom comes much sorrow." -- Ecclesiastes 1:18 (NIV)
Ayecarumba
Ayecarumba
  • Threads: 236
  • Posts: 6763
Joined: Nov 17, 2009
November 18th, 2015 at 11:19:22 PM permalink
If I have 2 sets of dice, 2 red and two blue, and throw all four at the same time, but only evaluate the totals by color, would it take ~62 "trials" to hit all the totals from 2 through 12, or only ~32 (since I am doubling my chance of hitting each number each "trial"? Doubling the combinations to 2,4,6, etc. Still returns 61.###
Simplicity is the ultimate sophistication - Leonardo da Vinci
BruceZ
BruceZ
  • Threads: 2
  • Posts: 57
Joined: May 23, 2015
November 19th, 2015 at 12:10:16 AM permalink
Quote: Dalex64

I put in ten 2's and a 1
You know, for the number of ways for at least one of the dice to be a certain number.

The answer was 36, which I think makes sense, you might expect to have to cycle through all 36 possibilities to see each of those 11 possibilities once.


The Wizard's program isn't set up to handle your question, but it should be easy to modify it so it can. His current program assumes that you are giving it all of the possible outcomes. If you put in ten 2's and a 1, his program will assume that there are 21 possible outcomes each with probability 1/21, whereas you want there to be 36 possible outcomes each with probability 1/36. A separate input would need to be provided for the total number of outcomes. Also, you don't want ten 2's and a 1 if you want the average number of rolls to get all 11 combinations that give you a certain number, say a six, on at least one die. You would want eleven 1's, and you'd need the separate input to specify 36 total outcomes. However, since all 11 events of interest have the same probability, it is easy to do this by hand as it is simply

36*(1/11 + 1/10 + 1/9 + 1/8 + 1/7 + 1/6 + 1/5 + 1/4 + 1/3 + 1/2 + 1/1)

≈ 108.71558 rolls.

That is, the probability of rolling the first qualifying outcome is 11/36, so it takes an average of 36/11 rolls to get it. Once you get it, the probability of rolling the second outcome is 10/36, so the average number of additional rolls to get the second after getting the first is 36/10. The third will take an additional 36/9, and so on. This is called the coupon collector problem.

Now perhaps you didn't want to distinguish the 2 dice, so for example, maybe you wanted (1,6) and (6,1) to be the same event, and you only need one of these. In that case you would want to enter five 2's and a 1 for a total of 6 events, and you'd still need the Wizard to provide the additional input for 36 total outcomes. This one is harder to do by hand since the probabilities of each event are not the same. The answer to that one comes to about 54.398701 rolls. This is called the generalized coupon collector problem, and it can be solved with the inclusion-exclusion principle. The Wizard has a good discussion of the method here.

I have written the R function below to answer all these questions.



gccp = function(total.outcomes, outcomes.per.event) {
E = total.outcomes/outcomes.per.event
L = length(outcomes.per.event)
T = E[1]
if (L > 1) T = T + outcomes.per.event[1]/(outcomes.per.event[1] + outcomes.per.event[2])*E[2]
if (L > 2) {
for (n in 3:length(outcomes.per.event)) {
p = 0
for (j in 1:(n-1)) {
terms = combn(outcomes.per.event[1:(n-1)],j)
for (k in 1:(length(terms)/j)) {
p = p + (-1)^(j+1) * outcomes.per.event[n]/(outcomes.per.event[n] + sum(terms[1:j,k]))
}
}
T = T + (1-p)*E[n]
}
}
cat("\nExpected trials for all events = ",T,"\n")
if (L > 1) {
cat("Probability of all before last = ",1-p,"\n")
cat("Odds against all before last = ",1/(1-p)-1,"to 1\n")
}
}


The first input is the total number of outcomes, and the second input is like the Wizard's - an array of numbers indicating how many outcomes there are per event. Additionally, it gives the probability and odds of getting all of the events except the final event before you get the final event, so you can use it to evaluate the Wynn bet (all numbers before a seven), all tall, all small, etc. If you only want the average number of rolls, then the order of the event inputs don't matter in either my script or the Wizard's. If you want the probability of getting all the other events before the final one, then place the number for the last event last, and the order of the others doesn't matter. For example, to evaluate the average number of rolls to get all of the numbers 2-12 in any order, and also the probability of getting the seven last, enter

> gccp(36,c(1,2,3,4,5,5,4,3,2,1,6))

For which the output is

Expected trials for all events = 61.217385
Probability of all before last = 0.0052577041
Odds against all before last = 189.19709 to 1


The expected trials is in agreement with the Wizard's example, and the probability and odds are correct for the Wynn bet. Note that the expected value is for rolling all of the numbers in any order - the seven doesn't have to be last. The seven being last only applies to the probability and odds.

If you want the average number of rolls to get all 11 outcomes that have a six on at least one die, enter

> gccp(36,c(1,1,1,1,1,1,1,1,1,1,1))

Expected trials for all events = 108.71558
Probabilty of all before last = 0.090909091
Odds against all before last = 10 to 1


In agreement with what we calculated above. If you don't want to distinguish the two dice so (1,5) = (5,1), etc., enter

> gccp(36,c(2,2,2,2,2,1))

Expected trials for all events = 54.398701
Probabilty of all before last = 0.36940837
Odds against all before last = 1.7070312 to 1
BruceZ
BruceZ
  • Threads: 2
  • Posts: 57
Joined: May 23, 2015
November 19th, 2015 at 3:36:47 AM permalink
Actually we can use the Wizard's program for the problem Dalex64 asked where we want the average number of rolls for some subset of the outcomes instead of all the outcomes. We just need to scale the result. So for the average number of rolls to get all 11 dice combinations that contain a six, we would enter eleven 1's in the program which produces 33.218651, and then multiply by 36/11 to get 108.71559. If we don't want to distinguish the dice, then enter 5 twos and 1 one into the program to get 16.621825, then multiply that by 36/11 to get 54.3987. Both of these agree with the results from my function above.

The Wizard's program could apply this scaling automatically by providing a separate input for total possible outcomes, and then multiply by this number divided by the sum of the input combinations.
Dalex64
Dalex64
  • Threads: 1
  • Posts: 1067
Joined: Feb 10, 2013
November 19th, 2015 at 5:29:13 AM permalink
Thanks, BruceZ, that was enlightening.
Wizard
Administrator
Wizard
  • Threads: 1520
  • Posts: 27118
Joined: Oct 14, 2009
November 19th, 2015 at 6:16:34 AM permalink
BruceZ, that was an amazing post! Welcome to the forum. My program uses the same technique you described at 2+2.

BTW, here is a link to the original discussion of the problem of rolling every total from 2 to 12.
"For with much wisdom comes much sorrow." -- Ecclesiastes 1:18 (NIV)
RS
RS
  • Threads: 62
  • Posts: 8626
Joined: Feb 11, 2014
November 19th, 2015 at 1:07:40 PM permalink
I typed in 5500 thirteen times and it gave me the answer of ~41?

Oh nvm. This thing's mad confusing.
BruceZ
BruceZ
  • Threads: 2
  • Posts: 57
Joined: May 23, 2015
November 19th, 2015 at 1:27:29 PM permalink
What's really amazing is that you can solve this using the Poisson "magic trick" similar to what I described in my first post on this forum. For rolling all numbers 2-12, we pretend that the dice are rolled at instants in time determined by a continuous Poisson points process of rate 1. Then the 11 numbers form 11 separate independent Poisson points processes of rate pn the probabilities of each number. We can compute the expected value of the number of rolls to get them all from

E(T) = integral {0 to infinity} P(T > t) dt.

The waiting times for each number will be exponentially distributed, so P(T > t) will be 1 minus the product of the terms like (1 - exp(-pn*t)). You could type the following into wolframalpha

integrate from 0 to infinity 1 - (1-exp(-t/36))^2*(1-exp(-2t/36))^2*(1-exp(-3t/36))^2*(1-exp(-4t/36))^2*(1-exp(-5t/36))^2*(1-exp(-t/6))

and it will give you the exact result

769767316159 / 12574325400 ≈ 61.217385

You could carry out this integral by hand since it is just a product of exponential terms, and if you did, you would end up with the same terms we got from inclusion-exclusion.
BruceZ
BruceZ
  • Threads: 2
  • Posts: 57
Joined: May 23, 2015
November 20th, 2015 at 9:59:52 AM permalink
There was a minor issue with my R script affecting the probability when you just put in 2 events. Of course that case is easy to compute by hand. Anyway, here's an update:



gccp = function(total.outcomes, outcomes.per.event) {
E = total.outcomes/outcomes.per.event
L = length(outcomes.per.event)
T = E[1]
if (L > 1) {
p = outcomes.per.event[2] / (outcomes.per.event[2] + outcomes.per.event[1])
T = T + (1-p)*E[2]
}
if (L > 2) {
for (n in 3:length(outcomes.per.event)) {
p = 0
for (j in 1:(n-1)) {
terms = combn(outcomes.per.event[1:(n-1)],j)
for (k in 1:(length(terms)/j)) {
p = p + (-1)^(j+1) * outcomes.per.event[n]/(outcomes.per.event[n] + sum(terms[1:j,k]))
}
}
T = T + (1-p)*E[n]
}
}
cat("\nExpected trials for all events = ",T,"\n")
if (L > 1) {
cat("Probability of all before last = ",1-p,"\n")
cat("Odds against all before last = ",1/(1-p)-1,"to 1\n")
}
}


It's common to make many updates to computer programs like this. When there was no time limit on editing, they could all be made to the original post instead of having to make a separate post for each one.

BTW, I have to avoid using i as an array index on this forum (in brackets) because the forum software interprets it as a formatting code and suppresses it even though it's inside the code tags. That would make the program not work. That was a hard bug to find the first time it happened.
Wizard
Administrator
Wizard
  • Threads: 1520
  • Posts: 27118
Joined: Oct 14, 2009
November 20th, 2015 at 11:49:40 AM permalink
Quote: BruceZ

E(T) = integral {0 to infinity} P(T > t) dt...



This is brilliant!!! I've just worked through a simplified version of this to prove to myself it works. To simplify the problem, consider these questions:

1. What is the expected number of rolls of two dice to achieve totals of both a 2 and 3?
2. You have two light bulbs where the lifespan is exponentially distributed. One has mean 36 days and the other 18 days. What is the expected number of days until the second one to burn out does so?

The answer in both cases is exactly 42 (if my math is right). I find this quite amazing if this "magic trick" always gives an exact answer as opposed to an approximation.

Isn't 42 also the meaning of life, at least according to the Hitchhiker's Guide to the Galaxy? Maybe now we know why.
"For with much wisdom comes much sorrow." -- Ecclesiastes 1:18 (NIV)
teliot
teliot
  • Threads: 43
  • Posts: 2871
Joined: Oct 19, 2009
November 20th, 2015 at 1:21:26 PM permalink
Quote: Wizard

Isn't 42 also the meaning of life, at least according to the Hitchhiker's Guide to the Galaxy?

As I recall, 42 is the "answer to the ultimate question" and much of the plot line concerns discovering the question that "42" answers. At the end, the ultimate question is finally disclosed. This ultimate question is, "what is 6 x 9?"

The puzzle for the readers here is, why is 6 x 9 = 42? (Don't look it up.)

So long, and thanks for all the fish.
Climate Casino: https://climatecasino.net/climate-casino/
BruceZ
BruceZ
  • Threads: 2
  • Posts: 57
Joined: May 23, 2015
November 20th, 2015 at 2:59:19 PM permalink
Quote: Wizard

Quote: BruceZ

E(T) = integral {0 to infinity} P(T > t)dt

This is brilliant!!! I've just worked through a simplified version of this to prove to myself it works.


We can see in the discrete case for a non-negative integer random variable N by adding these equations

P(N > 0) = P(N=1) + P(N=2) + P(N=3) + P(N=4) + ...
P(N > 1) = P(N=2) + P(N=3) + P(N=4) + ...
P(N > 2) = P(N=3) + P(N=4) + ...
P(N > 3) = P(N=4) + ....
...
------------------------------------------------------------------------------------------------------
sum {n=0 to ∞} P(N > n) = P(N=1) + 2*P(N=2) + 3*P(N=3) + 4*P(N=4) + ...

= E(N).

Intuitively that makes sense since each additional value of n will contribute 1 more to E(N) the fraction of the time that P(N > n). We can get the continuous case by letting N take on fractional values and then proceeding to the limit as these go to a continuum.



Quote: Wizard

To simplify the problem, consider these questions:

1. What is the expected number of rolls of two dice to achieve totals of both a 2 and 3?
2. You have two light bulbs where the lifespan is exponentially distributed. One has mean 36 days and the other 18 days. What is the expected number of days until the second one to burn out does so?

The answer in both cases is exactly 42 (if my math is right). I find this quite amazing if this "magic trick" always gives an exact answer as opposed to an approximation.


That's right, and it will always be exact, not an approximation. We are essentially turning the dice into light bulbs by forcing the dice to be rolled at instants of time determined by the continuous Poisson points process. But clearly the times at which we roll the dice have no effect on the average number of rolls it takes to get some numbers. The Poisson transformation makes their waiting times independent, whereas their waiting times for the discrete case are not independent.
DJTeddyBear
DJTeddyBear
  • Threads: 210
  • Posts: 11062
Joined: Nov 2, 2009
Thanked by
DRich
March 24th, 2021 at 7:45:29 PM permalink
The math on this is way over my head, but Mike discusses it in his latest column:
https://wizardofodds.com/ask-the-wizard/341/

What I love most about this column is that Mike provides an answer that goes 13 decimal places, but feels the need to precede that with the disclaimer “Approximately”! 🤪
I invented a few casino games. Info: http://www.DaveMillerGaming.com/ ————————————————————————————————————— Superstitions are silly, childish, irrational rituals, born out of fear of the unknown. But how much does it cost to knock on wood? 😁
DogHand
DogHand
  • Threads: 2
  • Posts: 1841
Joined: Sep 24, 2011
March 25th, 2021 at 8:22:59 PM permalink
Quote: teliot

As I recall, 42 is the "answer to the ultimate question" and much of the plot line concerns discovering the question that "42" answers. At the end, the ultimate question is finally disclosed. This ultimate question is, "what is 6 x 9?"

The puzzle for the readers here is, why is 6 x 9 = 42? (Don't look it up.)

So long, and thanks for all the fish.



Is it because...

... The answer is in base 13?


Dog Hand
unJon
unJon
  • Threads: 16
  • Posts: 4808
Joined: Jul 1, 2018
March 25th, 2021 at 8:31:40 PM permalink
Quote: DogHand

Is it because...

... The answer is in base 13?


Dog Hand



”I don’t make jokes in base 13.” - Douglas Adams
The race is not always to the swift, nor the battle to the strong; but that is the way to bet.
gordonm888
Administrator
gordonm888
  • Threads: 61
  • Posts: 5374
Joined: Feb 18, 2015
March 25th, 2021 at 9:34:02 PM permalink
Quote: Wizard

A while ago it was asked what is the expected number of rolls with two dice to achieve every total from 2 to 12. I just created an Expected Trials Calculator to answer such questions. Just put in the probability or number of combinations for up to 19 different outcomes (as many as JavaScript would take), click the calculate button, and viola -- your answer.




I tried this and got neither a viola or violin. Perhaps you meant "voila"?
So many better men, a few of them friends, are dead. And a thousand thousand slimy things live on, and so do I.
ChesterDog
ChesterDog
  • Threads: 9
  • Posts: 1730
Joined: Jul 26, 2010
March 26th, 2021 at 6:13:44 AM permalink
Quote: DogHand

Is it because...

... The answer is in base 13?


Dog Hand




9 x 6 = 54 = 4 x 13 + 2
That stands for a deck of playing cards--4 suits plus 2 jokers.

The ultimate answer would have something to do with randomness, as implied by the playing cards.
  • Jump to: