This problem as well as Marilyn von Savant’s name popped up a few times recenty, so it got my interest. Below is the R simulation which was suggeste by exercise 11.
# Monty Hall function
montyhallsim <- function(runs) {
outcome <- rep(0,n)
cardoor <- sample(1:3,n,replace=TRUE)
return (sum(cardoor!=1)/n)
}
# Initialize number of runs per each simulation
n <- 1000
# Run a single simulation
montyhallsim(n)
## [1] 0.665
Looks pretty close to 2/3. Let us run more simulations.
# Initialize number of simulations
simcount <- 1000
# Run simulations
winper <- replicate(n, montyhallsim(n))
# Plot results
library(ggplot2)
ggplot()+geom_histogram(aes(winper), binwidth=.003)+
xlab("Winning Percentage")+ylab("")
summary(winper)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.6200 0.6570 0.6670 0.6671 0.6760 0.7140
We can clearly see after 1000 simulations that the probability of winning a car with this stragegy is 2/3 (the mean for this run is 0.667077.
Here is an interesting, 5-minute video explaining a little more history behind the Monty Hall paradox.