A Conversation for The Monty Hall Problem

'tis true it seems

Post 1

kiwiozit

Actually I wasn't happy with this Monty thing being true so I decided to test it out with a short script -- and half expected to get 50/50 odds, but found it is actually as stated. Running the below (asp) script and outputing the results and running it through 100, 200, 1000, 5000 times it just gets closer and closer to 33%/66% odds the more times it runs. Changing it to 4 doors gets it to 25%/75% odds etc.
Funny thing is it seems obvious with the example given of 50 doors; the chances of you having got the right one is so low that it is very likely the only door left open is the one Monty couldn't open -- seems obvious with 50 doors, just not when you only mention 3, but the mathematics must actually be the same -- at least thats what my script says. smiley - smiley

With:3 doors, playing:10000 times; Don't Change:3336 / Change:6664 [33.36% vs 66.64%]

---script----
' Test Montys door problem

' Set up a randomization function
Randomize
Function Rand(Low,High)
Rand = Int((High - Low + 1) * Rnd) + Low
End Function

'Set variables
TotalLoops = 5000
'Doors
For TotalDoors = 3 to 20
CountWinsStay = 0
CountWinsChange = 0
'Loops
For x = 1 to TotalLoops
'Set the winning prize door
WinningDoor = rand(1,TotalDoors)
'Choose a door
DoorChoice = rand(1,TotalDoors)

'Monthy chooses a loosing door NOT to open [and opens the rest]
MontysChoice = WinningDoor
do until MontysChoice <> DoorChoice and MontysChoice <> WinningDoor
MontysChoice = rand(1,TotalDoors)
Loop

'Keep the score if keep original choice
if DoorChoice = WinningDoor then
CountWinsStay = CountWinsStay + 1
else
'Keep the score if change to other door
CountWinsChange = CountWinsChange + 1
end if
Next
' Output With:TotalDoors doors, playing:TotalLoops times; Don't Change:CountWinsStay / Change:CountWinsChange [CountWinsStay/TotalLoops*100% vs CountWinsChange/TotalLoops%]
Next


'tis true it seems

Post 2

Gnomon - time to move on

Logic 1 Intuition 0

smiley - biggrin


'tis true it seems

Post 3

kiwiozit

Exactly! smiley - smiley

Actually my code wasn't quite logical as sometimes it was getting Monty to open the wrong door (i.e. he'd open the winning door!) I suddenly realised whle in the shower this morning smiley - erm; but modifying it (as follows) makes fundementally no change to the result [especially as the wrong code only affected doors of 4 or more].


'Monthy chooses a door NOT to open [and opens the rest]
if DoorChoice = WinningDoor then
do until MontysChoice <> DoorChoice
MontysChoice = rand(1,TotalDoors)
Loop
else
MontysChoice = WinningDoor
end if


'tis true it seems

Post 4

TRiG (Ireland) A dog, so bade in office

I've done it in php for the three-door problem at F134469?thread=5099317. I want to edit the script so that it works for multiple doors. And ideally it should work in javascript, so it works locally instead of requiring page reloads. But I don't know any javascript yet.

TRiG.smiley - geek


Key: Complain about this post

Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."

Write an entry
Read more