Monty Monte Carlo

The Monty-Hall problem is a notorious mind-trap concerning conditional probabilities. You’re on a TV game show, and you get to choose one of three doors. Behind one of the doors is a car: the prize; behind the other two doors are goats: the booby prizes. After you choose your door, if you haven’t won, Monty Hall will open one of the other two doors and show you a goat. You now have one final chance to choose a closed door. At this point, one of the two remaining hides the car and the other hides a goat. The problem is whether you should change your original choice, or stick with the original choice. The mind trap is thinking that, when facing your final choice, you have a fifty-fifty chance of winning whether you change doors or stick with your original choice.

Rather than  detail the reasoning (the wikipedia article is fine for that), I’m going to write a little simulation that runs a large number of games and tracks the results for the two strategies. Amusingly, the reasoning will emerge as we write the simulation. This often happens: writing code forces you to understand the problem with sufficient clarity that you actually solve the problem in a mathematical way, by pure reason, in “closed form,” that obviates the need to do a simulation. Writing the simulation actually simulates the logic of the problem in your mind.

The distribution of outcomes is the same whether the car is behind door 1, door 2, or door 3, so it suffices to consider the one case where the car is behind door 1. Simulate your first choice with the following Mathematica function:

firstChoice[] := RandomInteger[{1, 3}];

which depends on the primitive RandomInteger. You win immediately if you choose 1, so Monty will always show you 2 or 3. Therefore, Monty’s choice does not depend on yours:

montyChoice[] := RandomInteger[{2, 3}];

Your final choice depends on your first choice, on Monty’s choice, and on your strategy. Model your strategy with a Boolean variable named switchQ. Use the primitive RandomChoice:

secondChoice[yourFirst_, montyChoice_, switchQ_] :=
    (* choose between door 1 and whatever monty didn't choose *)
    RandomChoice[{1, 5 - montyChoice}], 

By gum, we see it, don’t we? If you switch, you get a fifty-fifty chance; if you don’t switch, you only get a 1/3 chance. Amazing, but true. But, not to be daunted by reason, we will plow ahead with the simulation!

We run a round of the Monte-Carlo simulation as follows:

round[switchQ_] :=
   With[{f = firstChoice[]},
    If[f === 1,
     secondChoice[f, montyChoice[], switchQ]]];

Do a run of 300,000 games, tallying the results with the Tally and Table primitives, which fill up an array with data and then analyze it (watch this blog for a beautiful reactive, online form of this, later on!)

Tally@Table[round[True], {300000}]
~~> {{1, 200042}, {3, 50033}, {2, 49925}}

Ok, so about 2/3 of the time we win if we switch. How about if we don’t switch?

Tally@Table[round[False], {300000}]
~~> {{2, 99826}, {1, 100023}, {3, 100151}}

Only win 1/3 of the time! You double your chances by switching, it isn’t even close.

We can write another version of the simulation that pedantically imagines that after choosing door 1, we continue with the game, insisting that Monty show us a goat and that we pick some other door. In this case, Monty’s choice does depend on our choice, since he won’t show us 1.

Oddly, in this version, with the switch strategy, we lose only if we originally pick the winning door, but that’s just 1/3 of the time, so we win 2/3 of the time. If we don’t follow the switching strategy, then we win 1/3 of the time. The results are identical, and the following variant of the Monte-Carlo simulation bears this out.

firstChoice[] := RandomInteger[{1, 3}];

montyChoice[yourFirst_] :=
  If[yourFirst === 1,
    RandomInteger[{2, 3}],
    (* else *) 5 - yourFirst];

secondChoice[yourFirst_, montyChoice_, switchQ_] :=
     1, 5 - montyChoice,
     2, 1,
     3, 1],

round[switchQ_] :=
  With[{f = firstChoice[]},
    secondChoice[f,montyChoice[f], switchQ]];

~ by rebcabin on November 3, 2012.

3 Responses to “Monty Monte Carlo”

  1. This is quite fascinating problem, and what makes it so fascinating to me is how hard it is to find a simple, convincing way to guide someone to prove to themselves that it is indeed better “to switch” 🙂
    The explanation I have found most effective is to spell out the essence of the information exchange that skews probabilities.

    First, the player adds information by enforcing limitation on Monty’s choice, then the player use information that Monty have to show the goat. These two add up to the skewed probability of 1/3 to 2/3 for remaining doors vs. expected 1/2 to 1/2 in the case of no information exchange.
    It’s kind of like in those puzzles… “Would you tell me the …?” “No I would certainly not!” “Thanks, you’ve just told me the answer.”

  2. To Alex:

    Try this:

    Separate the three doors into a set with 1 door, and a set with 2 doors. Now tell the candidate to choose one of the sets.
    If the candidate chooses the set with 2 doors, and the car is behind one of them, you get the car.

    That should make anyone’s choice very straight forward :).

    To Brian:

    Awesome idea! My 14 year old self would probably still argue in disbelief, but a little part of me can now rest assured :).

  3. My intuition with problems like this is to take them to an extreme case and reason from there. If instead of three doors we have 1,000 doors … we pick one, and then Monty opens 998 of the remaining doors showing us that all of them have goats. It should be obvious that we should switch to the remaining unopened door.

    But here’s a trickier question 😀 what if Monty opens some smaller number of doors, let’s say 499. Should we stick with our original door? Or choose one of the remaining 500 unopened doors? What is our probability of winning the prize given each strategy?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: