The Monty Hall Paradox is an interesting probability problem I read online. The rules and discussion can be find here and you can actually play it here.

Although this binomial tree has well demonstrated why the player should always change his original choice in this game, a lot of people still belive the chance is always 50/50 no matter how you play. And I found their argument, based on the fact that the player will always have to choose one out of two doors at the end of the game, actually makes a lot sense intuitively, which makes it harder to argue against.

So why don’t we just make a test? And instead of manually testing it 20 or 30 times using an online simulator like the one above, why not to have a program that loops this game as many time as you want (or as your machine can bear).

In order to do that, I wrote a program in java. This program will ask you how many times you want to play the game and what strategy you want to stick with. Then it will start to simulate the game in the way you instructed and print out the final statistics. To make it completely fair, the program uses a random generator to decide which door the prize is hidden behind and which door the player chooses at the begining. The only thing that won’t change is the strategy you specify.

```/*********************************** Java code ***********************************/
import acm.program.*;
import acm.util.*;

public class MontyHallGame extends ConsoleProgram {

private int NUM_OF_CHOICES = 3;

public static void main(String[] args) {
new MontyHallGame().start(args);
}

public void run() {
setFont("Courier New-18-bold");
while (true) {
int trails = readInt("Time of experiments: ");
boolean change = readBoolean("Always switch choice?(true/false): ");
int wins = 0;
int loses = 0;
for (int i = 0; i < trails; i++) {
/** Assign the prize to a random choice */
int[] choices = new int[NUM_OF_CHOICES];
for (int j = 0; j < choices.length; j++) {
choices[j] = 0;
}
int prize = rgen.nextInt(0, choices.length - 1);
choices[prize] = 1;
/** Make the first call and remove one of the wrong choices */
int firstChoice = rgen.nextInt(0, choices.length - 1);
int removedChoice = firstChoice;
while (removedChoice == firstChoice || removedChoice == prize) {
removedChoice = rgen.nextInt(0, 2);
}
/** Decide to switch choice or not */
int finalChoice = firstChoice;
if (change) {
while (finalChoice == firstChoice || finalChoice == removedChoice) {
finalChoice = rgen.nextInt(0, choices.length - 1);
}
}
if (finalChoice == prize) {
wins++;
} else {
loses++;
}
}
/** display results */
println("Wins: " + wins);
println("Loses: " + loses);
println("Winning chance: " + (double)wins / (double)trails * 100 + "%");
println("");
}
}
// private instance random generator
private RandomGenerator rgen = RandomGenerator.getInstance();
}/*********************************** Java code ***********************************/
```

So, here are the results of playing “no” strategy 5000, 10000, and 100000 times respectively. (“No” is equal to “false” in the program. Sorry I was too lazy to enumarte the booleans with strings.) The chance of winning are 33.28%, 32.87%, and 33.331%.

And the results for “yes” strategy under the same conditions. The chance of winning are 65.92%, 66.91%, and 66.767%.

And to sum it up.

I’m glad to see the results are consistant with the outcomes of the binomial tree and hopefully this can be a satisfying answer to the 50/50 group.

roy