set NoChangeWin to 0
set NoChangeLose to 0
set YesChangeWin to 0
set YesChangeLose to 0
set TheDoors to {"Door 1", "Door 2", "Door 3"}
set TheChoices to {"Change Choice", "Don't Change Choice"}
set WinningDoor to some item in TheDoors
set ChosenDoor to some item in TheDoors
set ClosedDoors to {WinningDoor, ChosenDoor}
The next section chooses a door to open. Remember, this cannot be the Winning Door, nor can it be the contestant’s Chosen Door. So first we put all the possible doors to open into a list (this list could contain either one or two doors), then choose a random door from that list to open.
Then the next section puts the two remaining closed doors into a list for the contestant to choose from again.
set OpenDoors to {}
repeat with ThisDoor in TheDoors
if ThisDoor is not in ClosedDoors then
set end of OpenDoors to (ThisDoor as string)
end if
end repeat
set OpenDoor to some item in OpenDoors
set NewDoors to {}
repeat with ThisDoor in TheDoors
if (ThisDoor as string) is not OpenDoor then
set end of NewDoors to (ThisDoor as string)
end if
end repeat
The next section is just a little more complicated. First we get a random choice from that second list from the start of the script. This represents whether or not the contestant changes their mind about which door they want. Then we use some nested if statements to determine the results.
Firstly, if the choice is to NOT change, then we set the Final Door to be the same as the original Chosen Door. Then we check to see if the Final Door is the same as the Winning Door randomly selected at the start of the script. If it is, we add 1 to the NoChangeWin counter. If it’s not the same, we add 1 to the NoChangeLose counter.
The second part below – the else statement – is for when the contestant DOES choose to change doors. We use a quick repeat loop to select the other door from the list of two closed doors to be our Final Door. Then run the same analysis as above. If the Final Door is the same as the Winning Door, we add 1 to the YesChangeWin counter. If it’s not the same, we add 1 to the YesChangeLose counter.
set TheChoice to some item in TheChoices
if TheChoice is "Don't Change Door Choice" then
set FinalDoor to ChosenDoor
if WinningDoor = FinalDoor then
set NoChangeWin to NoChangeWin + 1
else
set NoChangeLose to NoChangeLose + 1
end if
else
repeat with ThisDoor in NewDoors
if (ThisDoor as string) is not ChosenDoor then
set FinalDoor to (ThisDoor as string)
end if
end repeat
if WinningDoor = FinalDoor then
set YesChangeWin to YesChangeWin + 1
else
set YesChangeLose to YesChangeLose + 1
end if
end if
The final part is our reporting. This simply creates four lines of text with the various outcomes (win after not changing, lose after not changing, win after changing, lose after changing)
return "Contestant wins after NOT changing : " & NoChangeWin & return & "Contestant loses after NOT changing : " & NoChangeLose & return & return & "Contestant wins after changing : " & YesChangeWin & return & "Contestant loses after changing : " & YesChangeLose
Now all we need to do is put the whole lot together and include a repeat loop to generate as many games as we please. I found that 1,000,000 games takes about 27 seconds to run. But that’s a bit ridiculous because you don’t really need more than 10,000 games to show the pattern.
Here is the complete script with commenting included. Plus, below that, a sample of the output for 10,000 games.
--these are counters to track wins/losses
set NoChangeWin to 0
set NoChangeLose to 0
set YesChangeWin to 0
set YesChangeLose to 0
-- this is the list of possible doors to choose at the start
set TheDoors to {"Door 1", "Door 2", "Door 3"}
-- this is the list of possible contestant choices at the end
set TheChoices to {"Change Choice", "Don't Change Choice"}
repeat 10000 times
-- randomly select a winning door
set WinningDoor to some item in TheDoors
-- randomly select the contestant's chosen door
set ChosenDoor to some item in TheDoors
-- put these into a list (they might be the same door)
set ClosedDoors to {WinningDoor, ChosenDoor}
-- randomly select a door to open
-- it can't be the winning door, nor the contestant's chosen door
set OpenDoors to {}
repeat with ThisDoor in TheDoors
if ThisDoor is not in ClosedDoors then
set end of OpenDoors to (ThisDoor as string)
end if
end repeat
set OpenDoor to some item in OpenDoors
-- set the NEW list of possible doors to choose
-- this is a list of two doors (now that one door is open)
set NewDoors to {}
repeat with ThisDoor in TheDoors
if (ThisDoor as string) is not OpenDoor then
set end of NewDoors to (ThisDoor as string)
end if
end repeat
-- randomly select if contestant will change their choice or not change
-- and count how often contestant wins vs loses
set TheChoice to some item in TheChoices
if TheChoice is "Don't Change Choice" then
set FinalDoor to ChosenDoor
if WinningDoor = FinalDoor then
set NoChangeWin to NoChangeWin + 1
else
set NoChangeLose to NoChangeLose + 1
end if
else
repeat with ThisDoor in NewDoors
if (ThisDoor as string) is not ChosenDoor then
set FinalDoor to (ThisDoor as string)
end if
end repeat
if WinningDoor = FinalDoor then
set YesChangeWin to YesChangeWin + 1
else
set YesChangeLose to YesChangeLose + 1
end if
end if
end repeat
return "Contestant wins after NOT changing : " & NoChangeWin & return & "Contestant loses after NOT changing : " & NoChangeLose & return & return & "Contestant wins after changing : " & YesChangeWin & return & "Contestant loses after changing : " & YesChangeLose
Contestant wins after NOT changing : 1663
Contestant loses after NOT changing : 3353
Contestant wins after changing : 3330
Contestant loses after changing : 1654
If you run this script for 10,000 games over and over again you’ll see very similar results. That is, you will win the Monty Hall game approximately twice as often if you change your choice when presented with the two doors.
Now this may seem counter-intuitive (it did for me) because, surely, if you’re presented with only two doors, you’ve got a fifty-fifty chance of picking the right door. I mean, there’s just two doors, so it shouldn’t really matter which one you choose … right?
Well, yes, that would be true if you had not already been presented with the three doors.
Here’s how it works …
You’re presented with three doors and you choose one. Let’s just say you choose the first door.

If you choose the first door, all the possible scenarios for the winning door look like this (below). And the same is the case if you choose the middle door or the last door – no matter which door you choose, there are three possibilities for the winning door.

Then Monty Hall opens one of the doors. In the first scenario, there’s a choice of two doors to open. In the other two, there’s only one door that could be opened.

But the kicker is this … you don’t know which of the three scenarios is in play. But looking at this diagram it should be obvious that out of the three possible scenarios, only one sees you winning if you keep the same door. Whereas there are two possible scenarios where you will win if you change.
Of course, this does not guarantee you a win if you change doors. But, on average, you’ll win twice as often if you change.
Keep grunting