Fred has five dice and decides to see how long it will take him
to throw five 6s using the following
procedure. He tosses all five dice.
He then picks up and re-tosses those
that are not 6s. He repeats this process
until he has all 6s.
What is the
expected number of tosses to get five
6s? Give the answer exactly in terms
of a fraction.
My solution:
3698650986/283994711 =~ 13.02366150755533
I did both a sim and an analytic approach.
In order to mitigate against the likelihood of a math error in calculating huge fractions, I wrote a function to add a list of fractions and return the reduced form of the solution.
For example, to add 1/2 + 1/3:
addfractionslist( [[1,2], [1,3]] )
returns ([5, 6], 0.8333333333333334)
Simulation (1,000,000 runs):
#dice sim analytic
1 6
2 8.723229 vs 96/11
=8.727272
3 10.540641 vs 10566/1001
= 10.555444
4 11.927555 vs 728256/61061
= 11.926696254565107
5 13.029266
13.017286
13.020303
13.016104
vs 3698650986/283994711 = 13.02366150755533
Analytic:
Call p(d,n) the probability of getting 'n' 6s by rolling 'd' dice once.
p(d,n) = comb(d,n)*(1/6)^n*(5/6)^(d-n)
Let:
a=expected value until 1 6 with 1 die
b=expected value until 2 6s with 2 dice
c=expected value until 3 6s with 3 dice
d=expected value until 4 6s with 4 dice
e=expected value until 5 6s with 5 dice
a=6
b = (25/36)(1+b) + (10/36)(1+a) + (1/36)(1)
b = 96/11
c = (125/216)(1+c) + (3*25/216)(1+b) + (3*5/216)(1+a) + (1/216)(1)
c = 10566/1001
d = (625/1296)(1+d) + (4*125/1296)(1+c) + (6*25/1296)(1+b) + (4*5)(1+a) + (1/1296)(1)
1296d - 625d = 625 + 500 + 500(10566/1001) + 150 + 150(96/11) + 20 + 20(6) + 1
671d = 1416 + 500(10566/1001) + 150(96/11)
671d = 1416 + 599400/91
671d = 728256/91
d = 728256/61061 = 11.926696254565107
e = (3125/7776)(1+e) + (5*625/7776)(1+d) + (10*125/7776)(1+c) + (10*25)(1+b) + (5*5)(1+a) + (1/7776)(1)
7776e - 3125e = 3125 + 3125 + 3125d + 1250 + 1250c + 250 + 250b + 25 + 25a + 1
4651e = 7776 + 3125(728256/61061) + 1250(10566/1001) + 250(96/11) + 25(6)
4651e = 7926 + 3125(728256/61061) + 1250(10566/1001) + 250(96/11)
4651e = 7926 + 3214681500/61061
4651e = 3698650986/61061
e = 3698650986/283994711 = 13.02366150755533
The analytic results agree well with the simulation results.
---------
def addfractionslist(alist):
""" alist is a list of lists. Each list, [a,b], is a list of 2 integers [numerator, denominator] ; return list of 2 integers """
if len(alist) == 1:
a = alist[0]
b = [0,1]
else:
a = alist[0]
b = alist[1]
num = a[0]*b[1] + a[1]*b[0]
den = a[1]*b[1]
mygcd = gcd(num,den)
ans = [int(num/mygcd), int(den/mygcd)]
if len(alist) == 2:
return ans, ans[0] / ans[1]
for i in range(2, len(alist)):
a = ans
b = alist[i]
num = a[0]*b[1] + a[1]*b[0]
den = a[1]*b[1]
mygcd = gcd(num,den)
ans = [int(num/mygcd), int(den/mygcd)]
return ans, ans[0] / ans[1]
import random
score = []
reps = 1000000
for iter in range(reps):
dice = 5 # plug in number of dice
for n in range(1,100):
toss = [random.randint(1,6) for i in range(dice)]
count6 = toss.count(6)
dice -= count6
if dice < 1:
score.append(n)
break
print(sum(score)/reps)
|
Posted by Larry
on 2025-02-05 08:32:27 |