The Monty Hall Simulation in Excel
The Rules of the Game Do you switch?? There are 3 doors to choose from Randomly placed behind one of the doors is a NEW CAR! Behind each of the other two doors is a donkey You are asked to choose a door The host then opens a door you did not choose and shows you a donkey You are then asked if you would like to switch to the remaining closed door Do you switch??
Useful Excel Functions =randbetween(lower_bound, upper_bound) generates a random integer between and including the bound numbers =rand() generates a random decimal number between 0 and 1 =if(condition, value_if_true, value_if_false) tests for a logical condition; returns specified value if condition is true or an alternate specified value if condition is false this is our “decision maker” function =sum(cell:cell) sums up all cells specified; the colon is used to express a range of cells
Divide and Conquer We are going to break our larger problem down into sub-problems for easier coding We will consider three cases In each, the car will be known to be behind a particular door Combining the results of the three cases will provide an understanding of the larger situation
Case 1: Car Behind Door #1 Contestant Chooses a Door Our main usage of random numbers will be for the contestant’s random selection of a door, as the first step of the game Use a formula to generate a random number for the contestant’s selection of door #1, 2, or 3
Case 1: Car Behind Door #1 How does the host decide which door to open? The host will never open the door the contestant selected, so we know Door #1 cannot be opened. However, this might be a good condition to logically check for… These True/False questions can be coded with the “if” function
Case 1: Car Behind Door #1 So, do you switch doors? It is simpler to code the logic that determines whether the contestant would have won if he/she stayed with the original door selection use the “if” function to do this Logically, if the contestant would have won by staying with the original door selection, he/she would have lost having switched doors use the “if” function to code this based off of the win by staying value
Case 1: Car Behind Door #1 (formulas for first game played) Remember to add sums at the bottom of the win columns to total the number of games won either staying or switching
Write the coding for the other two cases, where the car is known to be behind Door #2 and Door #3