Monty Hall paradox

I was watching the latest episode of Mythbusters where they tried to see if the Monty Hall paradox was true:

Suppose you’re on a game show, and you’re given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1 [but the door is not opened], and the host, who knows what’s behind the doors, opens another door, say No. 3, which has a goat. He then says to you, “Do you want to pick door No. 2?” Is it to your advantage to switch your choice?

Through different experiments they conclude that no one switches and you win more often by switching.

I remember learning about this in maths, so the results didn’t surprise me, but it’s still difficult not to fall into the trap of thinking that both doors still have a 50% chance after one of them have been opened. The problem lies in that the host knows which door has the car and the host opens the door after you pick your door. You can read about the problem here: http://en.wikipedia.org/wiki/Monty_Hall_problem

Naturally I wanted to test this programmatically, so I created this java code to test the paradox for 1 million games:

		int wins = 0;
		int gameNr = 0;
		Random random = new Random();
		for (; gameNr < 1000000; gameNr++) {
			// Host chooses a random winning door
			int winningDoor = random.nextInt(3);

			// Player chooses a random door
			int chosenDoor = random.nextInt(3);

			// Host opens a door that is not the winning or chosen.
			int openDoor;
			do {
				openDoor = random.nextInt(3);
			} while (openDoor == winningDoor || openDoor == chosenDoor);

			// Player switches his choice
			chosenDoor = 5 % (chosenDoor + openDoor + 2);

			// Host reveals the players choice and sees what's behind
			if (chosenDoor == winningDoor)
				wins++;
		}

		System.out.println("Wins: " + wins);
		System.out.println("Loses: " + (gameNr - wins));

The result confirms the mythbusters conclusion:

Wins: 667297
Loses: 332703

Skriv et svar

Din e-mail-adresse vil ikke blive offentliggjort. Krævede felter er markeret med *

*

Disse HTML koder og attributter er tilladte: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>