The following problem has been posted on Mensa International Facebook Page:
$\quad\quad\quad\quad\quad\quad\quad\quad$
The post itself received 1000+ comments but I won't go into details about the debate there since I know this is Bertrand's box paradox and the answer is $\frac23$. What make me interested here is how does one answer this problem using a Monte Carlo approach? How is the algorithm to solve this problem?
Here is my attempt:
- Generate $N$ uniformly distributed random numbers between $0$ and $1$.
- Let the event of box contains 2 gold balls (box 1) selected be less than half.
- Count the numbers that less than $0.5$ and call the result as $S$.
- Since it's a certainty to get a gold ball if the box 1 is selected and it's only 50% chance of getting a gold ball if the box 2 is selected, hence the probability of getting a sequence GG is $$P(B2=G|B1=G)=\frac{S}{S+0.5(N-S)}$$
Implementing the algorithm above in R:
N <- 10000
S <- sum(runif(N)<0.5)
S/(S+0.5*(N-S))
The output of program above is around $0.67$ which almost match with the correct answer but I'm not sure this is the correct way. Is there a proper way to solve this problem programmatically?