Probability of getting a boxcars in a game of craps after 24 throws¶
Faisal Qureshi
faisal.qureshi@ontariotechu.ca
http://www.vclab.ca
Copyright information¶
© Faisal Qureshi
License¶
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.Boxcars¶
In the game of craps, "boxcars" refers to rolling a total of $12$ with two dice.
Sovling analytically¶
Probability of getting a $(6,6)$ in a series of 24 two-dice throws
- Prob. of getting a $6$ = $1/6$
- Prob. of getting a $(6,6)$ = $(1/6) \times (1/6) = 1/36$, assuming independence
- Prob. of not getting a $(6,6)$ = $1 - 1/36 = 35/36$
- Prob. of not getting a single $(6,6)$ in $24$ tries = $(35/36)^{24}$
- Prob. of getting at least one $,(6,6)$ in $24$ tries = $1 - (35/36)^{24}$
In [11]:
p_analytical = 1. - (35. / 36)**(24)
print ('Prob. of getting at least one (6,6) in 24 tries', p_analytical)
Prob. of getting at least one (6,6) in 24 tries 0.4914038761309034
Setting up a Monte Carlo Simulation¶
In [12]:
import numpy as np
import matplotlib.pyplot as plt
import random
In [13]:
def throw_dice():
return random.choice([1,2,3,4,5,6])
def throw_two_dice(num_times):
dice_throws = []
for i in range(num_times):
dice_throws.append((throw_dice(), throw_dice()))
return dice_throws
In [14]:
print ('Dice throw outcome:', throw_dice())
Dice throw outcome: 3
In [15]:
print ('Two dice throw outcome:', throw_two_dice(1))
Two dice throw outcome: [(4, 1)]
In [16]:
def crap_boxcar(num_dice_throws):
success = 0.
outcomes = throw_two_dice(num_times = num_dice_throws)
for i in outcomes:
if i == (6,6):
success += 1
return success
In [17]:
num_throws = 24
print(crap_boxcar(num_throws), 'out of', num_throws)
2.0 out of 24
In [18]:
def simulate_crap_boxcar(num_trials):
success = 0.
for i in range(num_trials):
if crap_boxcar(24) >= 1: # We got at least one (6,6) in this series of
success += 1 # 24 two-dice throws
return success / num_trials
In [19]:
num_trials = 10
p_monte_carlo = simulate_crap_boxcar(num_trials = num_trials)
print ('Probability of getting (6,6) in a series of 24 two-dice throws', p_monte_carlo)
Probability of getting (6,6) in a series of 24 two-dice throws 0.6