PDA

View Full Version : Friday discussion - Monty Hall



mvidas
06-23-2006, 10:50 AM
Hi everyone,

As stated above, this is more for discussion than a question, or even just something to think about.

So I stumbled across this article in the wikipedia:
http://en.wikipedia.org/wiki/Monty_Hall_problem

Givens: 3 doors to choose from. 1 contains a car, the other 2 contain a goat. You make your choice of a door. After you choose, one of the remaining doors is revealed to you to show a goat. You then have the option of either staying with your original choice, or switching to the other unopened door.
Presumption from the wikipedia link above: You have a better chance of getting the car if you switch.

Though it did make sense, I still couldn't really believe it. After you are shown a door, there are 2 left. One with a car, one with a goat. Common sense tells me its like flipping a coin: the past means nothing, should be a 50/50 chance. But there are some massive mathematical formulas on the link that seem to say otherwise. Being as I often think in code, I figured I'd put my thoughts down in the vbe and run a few tests. To my surprise, it was exactly as they said; if you switch your guess when there are only 2 left, you have a higher chance than if you stay. Who knew!

I'm secretly hoping I have a mistake in logic here, if you can find it please tell me!Sub MontyHallProblem()
'http://en.wikipedia.org/wiki/Monty_Hall_problem
Dim TheDoors(1 To 3) As String, SheetData(1 To 50001, 1 To 7)
Dim i As Long, j As Long, WinCount As Long
Dim TheCar As Long, GimmeGoat As Long
Dim InitialGuess As Long, SwitchGuess As Long

'Test this 50,000 times
For i = 1 To 50000
'unnecessary, but I still stuck it in here
Randomize Int(Rnd() * Int(Rnd() * 10000000 + 1) + 1)

'Initialize doors
TheDoors(1) = "GOAT"
TheDoors(2) = "GOAT"
TheDoors(3) = "GOAT"

'Make your guess
InitialGuess = Int(Rnd() * 3 + 1)

'Put the car in one of the doors
TheCar = Int(Rnd() * 3 + 1)
TheDoors(TheCar) = "CAR"

'Choose the "Gimme Goat"
GimmeGoat = Int(Rnd() * 3 + 1)
Do Until GimmeGoat <> TheCar And GimmeGoat <> InitialGuess
GimmeGoat = Int(Rnd() * 3 + 1)
Loop

'Assign the door variable if you switch your door after the gimme
SwitchGuess = Int(Rnd() * 3 + 1)
Do Until SwitchGuess <> GimmeGoat And SwitchGuess <> InitialGuess
SwitchGuess = Int(Rnd() * 3 + 1)
Loop

'Populate array with data and outcome
SheetData(i, 1) = TheDoors(1)
SheetData(i, 2) = TheDoors(2)
SheetData(i, 3) = TheDoors(3)
SheetData(i, 4) = InitialGuess
SheetData(i, 5) = GimmeGoat
SheetData(i, 6) = IIf(TheDoors(InitialGuess) = "CAR", "YOU WIN!", "")
SheetData(i, 7) = IIf(TheDoors(SwitchGuess) = "CAR", "YOU WIN!", "")
Next

'Count the wins for each, put in last row of array
For i = 6 To 7
WinCount = 0
For j = 1 To 50000
If SheetData(j, i) = "YOU WIN!" Then WinCount = WinCount + 1
Next
SheetData(50001, i) = Format(WinCount, "#,##0 cars won")
Next

'Put the data into a worksheet
Application.ScreenUpdating = False
Workbooks.Add 1
Range("A1:G1").Value = Array("Door 1", "Door 2", "Door 3", "Your Guess", _
"GimmeGoat", "If you stay", "If you switch")
Range("A2:G50002").Value = SheetData
Columns.AutoFit
Range("A2").Select
ActiveWindow.FreezePanes = True
Application.ScreenUpdating = True
Range("G50002").Select
End Sub
As Fridays are often a little slower around here, why not?

EDIT: For what it was worth, I tried fixing my initial guess to always choose door #1 in the beginning:
'Make your guess
InitialGuess = 1 'Int(Rnd() * 3 + 1)
No change to the outcome.

Matt

mdmackillop
06-23-2006, 01:40 PM
The logic of this is that if there were 4 doors and the Compere opened 2 to show you goats, switching would increase your win ratio from 2 to 1 up to 3 to 1.
Regards
Malcolm

lenze
06-23-2006, 02:00 PM
This is nothing more then the principle of "Restricted Choice",(and does not require code) a term developed in the 30's to evaluate the best play in bridge where a guess was involved. The premise is really quite simple. If you have in fact chosen the CORRECT door, the emcee has a choice of which door to show you. If. however you have chosen the wrong door, the emcee only has one choice to show you. His choice is RESTRICTED. It is twice as likely that he has NO choice then that he does have a choice. The actual odds are 2 to 1 in favor of switching.

I can talk about this for hours. It's one of my favorite subjects.

HTH

lenze

malik641
06-23-2006, 05:08 PM
You know, at first, I didn't believe that. Like Matt didn't. But when I kept reading it started to make sense. Your chances of winning the car are ALWAYS 1/3 at the beginning, as you have no leads of which door would be correct. So you ALWAYS have a 2/3 chance of losing AT FIRST. After the host shows a goat, you have a lead...increasing your chances 1/3 extra which would be 2/3 probability by switching (because your chances would stay at 1/3 if you chose NOT to switch)....since you MOST LIKELY (2/3 chance) picked the wrong door to begin with.

I took a Logic class before I got my associates, and it would have made it SO much more interesting if the teacher brought this problem into it :yes

Thanks for this discussion, Matt :thumb and nice coding, BTW

mvidas
06-24-2006, 05:06 AM
I was having a blast with this problem yesterday at work, as it defied what I thought would have happened. I couldnt even get back to my regular work right away as my head was still stuck on this :)

I had modified it to have more doors, and saw that even with 4 doors (whether the host opens just one or two to show you), the odds are still increased to switch. Fun stuff!

Great explanation, lenze, when you explain it from the other point of view it actually makes much more sense! I'll admit I didn't read the entire wikipedia article, but if that isn't mentioned it there you may want to add that to it.

Matt

Jacob Hilderbrand
06-25-2006, 12:00 AM
Also this is not the same as flipping a coin at the end, since the coin toss would be independant of any previous tosses, but in the case of picking a door, the prize door is fixed so the past is important.

But basic logic is along these lines (at least in my mind).

You make a choice at the beginning. You have 1/3 chance of being right and 2/3 chance of being wrong. Knowing that you are likely to pick the wrong choice and also having the second wrong choice revealed, the remaining choice has a better change of being the one you want.

But it is still all up to chance, so if you already have a sure thing, don't risk it for what's behind door #3...

:)

nitt1995
07-14-2006, 10:58 AM
Thanks for the code. Another way to look at this problem is to assume there were 100 doors, and only one car. After you pick your door, the MC opens up 98 doors to show you two remaining doors (the one you picked and one other). I think it is pretty obvious here that you switch.

This logic is based upon the often-neglected qualifier that the MC must ALWAYS show a door AND that the MC knows what is behind the doors. If the MC has the option to show a door, this is now a game theory problem where the probability and conditions of showing the door must be considered.

Without the qualifiers, the MC could only show a door when the MC knows that you selected the right door, or conditionally show a door based upon which door you select.