
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.

The car and the goats were placed randomly behind the doors before the show.



Rules of the game

After you have chosen a door, the door remains closed for the time being.

The game show host, Monty Hall, who knows what is behind the doors, now has to open one of the two remaining doors, and the door he opens must have a goat behind it.

If both remaining doors have goats behind them, he chooses one randomly.

After Monty Hall opens a door with a goat, he will ask you to decide whether you want to stay with your first choice or to switch to the last remaining door.

Imagine that you chose Door 1 and the host opens Door 3, which has a goat.

He then asks you "Do you want to switch to Door Number 2?"



The question

Is it to your advantage to change your choice?



Note

The player may initially choose any of the three doors (not just Door 1), that the host opens a different door revealing a goat (not necessarily Door 3), and that he gives the player a second choice between the two remaining unopened doors.



Task

Run random simulations of the Monty Hall game. Show the effects of a strategy of the contestant always keeping his first guess so it can be contrasted with the strategy of the contestant always switching his guess.

Simulate at least a thousand games using three doors for each strategy and show the results in such a way as to make it easy to compare the effects of each strategy.



References

 Stefan Krauss, X. T. Wang, "The psychology of the Monty Hall problem: Discovering psychological mechanisms for solving a tenacious brain teaser.", Journal of Experimental Psychology: General, Vol 132(1), Mar 2003, 3-22 DOI: 10.1037/0096-3445.132.1.3
 A YouTube video:   Monty Hall Problem - Numberphile. 


<cfscript>
    function runmontyhall(num_tests) {
	// number of wins when player switches after original selection
	switch_wins	= 0;
	// number of wins when players "sticks" with original selection
	stick_wins  = 0;
	// run all the tests
	for(i=1;i<=num_tests;i++) {
	    // unconditioned potential for selection of each door
	    doors 	= [0,0,0];
	    // winning door is randomly assigned...
	    winner 	= randrange(1,3);
	    // ...and actualized in the array of real doors
	    doors[winner] = 1;
	    // player chooses one of three doors
	    choice 	= randrange(1,3);
	    do {
		// monty randomly reveals a door...
		shown = randrange(1,3);
	    }
	    // ...but monty only reveals empty doors; 
	    // he will not reveal the door that the player has choosen
	    // nor will he reveal the winning door
	    while(shown==choice || doors[shown]==1);
	    // when the door the player originally selected is the winner, the "stick" option gains a point
	    stick_wins  += doors[choice];
	    // to calculate the number of times the player would have won with a "switch", subtract the
	    // "value" of the chosen, "stuck-to" door from 1, the possible number of wins if the player
	    // chose and stuck with the winning door (1), the player would not have won by switching, so
	    // the value is 1-1=0 if the player chose and stuck with a losing door (0), the player would
	    // have won by switching, so the value is 1-0=1
	    switch_wins += 1-doors[choice];
	}
	// finally, simply run the percentages for each outcome
	stick_percentage	= (stick_wins/num_tests)*100;
	switch_percentage	= (switch_wins/num_tests)*100;
	writeoutput('Number of Tests:  ' & num_tests);
	writeoutput('<br />Stick Wins: ' & stick_wins & '  ['& stick_percentage &'%]');
	writeoutput('<br />Switch Wins: ' & switch_wins & '  ['& switch_percentage &'%]');
    }
    runmontyhall(10000);
</cfscript>