In: Computer Science
Part 2. Monty Hall problem:
Given below is the description of the problem.
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.
The rules are:
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 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?" Is it to your advantage to change your choice?
NOTES:
Using Bayes’ Theorem to Solve the Monty Hall Problem
Credit goes to Christopher Long for this interesting solution. I’m going to assume that you are familiar with Bayes’ Theorem, which is a way to figure out conditional probability (if event A happens, what’s the probability event B will happen?).
The basis for the solution is the same as in the above scenario. There are three doors, one has the car behind it. You pick a door, then Monty opens one of the other doors to reveal a goat.
Let’s assume you pick door 1 and then Monty shows you the goat behind door 2. In order to use Bayes’ Theorem we need to first assign an event to A and B.
Here’s the Bayes’ solution
:

Pr(A) is pretty simple to figure out. There is a 1/3 chance that
the car is behind door 1. There are two doors left, and each has a
1/2 chance of being chosen — which gives us Pr(B|A), or the
probability of event B, given A.
Pr(B), in the denominator, is a little trickier to figure out.
Consider that:
As Monty has opened door 2, you know the car is either behind door 1 (your choice) or door 3. The probability of the car being behind door 1 is 1/3. This means that the probability of the car being behind door 3 is 1 – (1/3) = 2/3. And that is why you switch.