Back to Nike Missile Home PageRelated to the "Bertrand's box paradox" of 1889 ## The Three Doors Problem

and Three Prisoners problem, and the Monty Hall problem, all the same logically.

Table of Contents

- Problem statement

-Surprising Correct Answer

-The output of the simulation code agreed with Randy :-((

-An Approach to the Correct Answer

-Here is the (FreeBasic) codeSon (Randy) posed the following problem.

Problem statement

The Three Doors (or Monty Hall) Problem

- a million dollars $ behind one

- a pile of poop behind one

- a tiger behind one

You (guest) choose one door

Host

- opens another door which does not have the million $

- does not reveal what is behind guest chosen door

You (the guest) get to choose whether to

a) stay with your original choice

b) flip the choice to the other closed doorIs plan a) or b) better ?????

Randy said that to flip your choice was the best answer.

I disagreed with his answer.

He was adamant, so I wrote some code (below, with random choices) to prove him wrong.

The output of the simulation code agreed with Randy :-((

There does not seem a logical error in my code.

Here is the output of the running simulation.

Starting BehindDoors, at 07-06-2017 18:19:14 Guest sticks with original selection

10000000 Iterations - Guest wins % 33.3319633331963Guest flips on even iterations

10000000 Iterations - Guest wins % 50.0038350003835Guest always flips

10000000 Iterations - Guest wins % 66.6403366640337All done!

Terminating BehindDoors, at 07-06-2017 18:19:25

An Approach to the Correct Answer

(Part of an e-mail from Randy - Gina is his wife - )Sounds good to me - I even understand it at this overview level :-))

Gina is happy you also don't understand. (Now she doesn't feel alone.) But she did say, "well, if there are only two outcomes, you can win or lose, and without switching you lose 33% of the time, then with switching you must win 66% of the time."

Here is the (FreeBasic) code

' GOAL ' solve a probability problem ' Background - ' three doors ' a million dollars $ behind one ' a pile of poop behind one ' a tiger behind one ' you choose one door ' host ' opens another door which does not have the million $ ' does not reveal what’s behind guest chosen door ' you (the guest) get to choose whether to ' a) stay with your original choice ' b) switch to the other closed door ' -------------------------- ' There is a big uproar about ' is it better to stay with original choice ' flip choice to other closed door, under which conditions ' ' ' Plan of Attack ' using the language supplied random number generator, ' a) set the three items behind random doors ' b) have guest choose a door ' c) have host open a non-winning door ' say 10,000 times ' Use successive phases to ' 1) stick with guest door - probability of winning ' 2) random have guest change selected door ' 3) change selected door to non-shown door ' ------------ ' The Report we want to make is ' a) assurance of probability (random number generator) working ' b) statistics of each each successive phase, including ' - % which behind which door ' - % which door initial choice ' - % win ' ' Format of report '" date/time phase # ' phase rules (1,2,3 above) ' Summary ' % $ behind which door ' % guess chooses which door ' % guest win, poop, tiger ' Details of last 5? sequences, (in "Plan of Attack") ' a) what behind each door ' b) guest 1st choice ' c) host shown door ' d) guest final choice ' '------------------- ' set monitor to 1280 x 1024 ' adapted to write and read the Accumulator array ' % integer +-32K ' & long integer +-2 billion ' ! single prcision float 7 places*10^+-38 ' # double precision float 15 places*10^+-300 ' $ st-ring - bug - error report on correct spelling? ' ' lets do it specifically, not generally say with n doors ;-)) ' so - array of three doors Dim shared Phase as integer ' 1 thru 3, used to determine what the guest does dim shared Iteration as integer dim shared RandInt as integer ' random integer between 1 and 3 dim shared x, y, z as integer ' working variables DIM Shared BehindDoor(3) as Integer ' values behind doors Const Tiger = 1 Const Poop = 2 Const Million = 3 Const debug = 0 DIM Shared GuestChoice as Integer DIM Shared GuestFlip as Integer DIM Shared HostChoice as Integer dim shared GuestWins as Integer dim shared GuestTrys as Integer ' ' Statistical Data Fields dim shared SDoorTotals(3) as integer dim shared SDoorTiger(3) as integer dim shared SDoorPoop(3) as integer dim shared SDoorMillion(3) as integer 'DEFDBL A-Z ' default everything to double float, not DEFSNG 'DEFSNG A-Z ' default everything to single float, not DEFDBL - AH - color!! ' well, it fails on DEFSNG - what is going on?? - what needs double? Trig?? Option Explicit ' Constants 'transparincies CONST White = &hFFFFFF ' colors CONST Grey = &h606060 CONST GreyL = &hA0A0A0 CONST Red = &hFF0000 CONST RedDull = &h800000 CONST Yellow= &hFFFF00 CONST YellowDull = &h808000 CONST Green = &h00FF00 CONST Blue = &h0000FF CONST BlueDull = &h000080 CONST Black = &h000000 ' this subroutine is used because occasionally ' RandInt is returned as zero ' Goal, return a random integer value, RandInt, between 1 through 3 Sub FindRandInt RandInt = 0 while ((RandInt < 1) or (RandInt > 3)) RandInt = (rnd(1)*3)+0.5 ' get a WEnd End Sub Sub XFlip dim yy as integer Select Case GuestChoice Case 1 if HostChoice = 2 then yy =3 else yy = 2 endif Case 2 if HostChoice = 1 then yy =3 else yy = 1 endif Case 3 if HostChoice = 1 then yy =2 else yy = 1 endif End Select GuestChoice = yy End Sub SCREEN 21, 32, 1,0 ' 15 ' 14 ' 12 '13 ' 16-512x384; 17-640x400; 18-640x480; 19-800x600; 20-1024x768; 21-1280x1024 Randomize timer print "" print "The Three Doors Problem" print " - a million dollars $ behind one" print " - a pile of poop behind one" print " - a people eating tiger behind one" print " You (guest) choose one door" print " Host " print " - opens another door which does not have the million $" print " - does not reveal what is behind guest chosen door" print " You (the guest) get to choose whether to" print " a) stay with your original choice" print " b) flip the choice to the other closed door" print "Is plan a) or b) better ?????" print " Open "C:\FreeBasic\3Doors.txt" for Output as #1 print #1,"" print #1,"The Three Doors Problem" print #1," - a million dollars $ behind one" print #1," - a pile of poop behind one" print #1," - a people eating tiger behind one" print #1," You (guest) choose one door" print #1," Host " print #1," - opens another door which does not have the million $" print #1," - does not reveal what is behind guest chosen door" print #1," You (the guest) get to choose whether to" print #1," a) stay with your original choice" print #1," b) flip the choice to the other closed door" print #1,"Is plan a) or b) better ?????" print #1," '---------------------------------- Print "press any key to continue" WHILE INKEY$ = "": sleep (10):WEND Print "" print "Starting BehindDoors, at ";date$,time$() Print "" Print #1,"" print #1,"Starting BehindDoors, at ";date$,time$() Print #1,"" Phase = 1 while (Phase < 4) ' see meaning of Phase above Select Case Phase Case 1 print "Guest sticks with original selection" print #1,"Guest sticks with original selection" Case 2 Print "Guest flips on even iterations" Print #1,"Guest flips on even iterations" Case 3 Print "Guest always flips" Print #1,"Guest always flips" Case else Print "XXXXXXXXX bad case" End Select ' clear statistics counters for x = 1 to 3 SDoorTotals(x) = 0 SDoorTiger(x) = 0 SDoorPoop(x) = 0 SDoorMillion(x) = 0 next x GuestWins = 0 GuestTrys = 0 '-------------- Iteration = 1 While (Iteration < 10000000) FindRandInt BehindDoor(1) = RandInt FindRandInt BehindDoor(2) = RandInt ' *** a subroutine to set a 0 < random int < 4 FindRandInt BehindDoor(3) = RandInt ' *** a subroutine to set a 0 < random int < 4 While (BehindDoor(1) = BehindDoor(2)) ' get a different value into BehindDoor2 FindRandInt BehindDoor(2) = RandInt ' *** a subroutine to set a 0 < random int < 4 WEnd While ( (BehindDoor(3) = BehindDoor(1)) or (BehindDoor(3) = BehindDoor(2))) FindRandInt BehindDoor(3) = RandInt ' *** a subroutine to set a 0 < random int < 4 WEnd ' we now have three unequal values behind all three doors ' 'OK, we have the doors set up, lets do the guest selection FindRandInt ' new random # GuestChoice = RandInt ' guest chooses this (random) door ' now host has to choose guest door not and million door not FindRandInt ' new random # while ( (GuestChoice = RandInt) or (BehindDoor(RandInt) = Million )) FindRandInt WEnd HostChoice = RandInt ' ok, we have the door that host opens ' now compute the door for GuestFlip ' rules, not the door the host opens if (Iteration<6 and debug) then Print "Iteration=";Iteration,BehindDoor(1),BehindDoor(2),BehindDoor(3) print "GuestChoice =";GuestChoice,"HostChoice = ";HostChoice, if (BehindDoor(GuestChoice) = Million) then print "Guest wins" else print "XXXX" Endif EndIf Select Case Phase case 1 ' dont flip Case 2 ' flip on even if NOT ( Iteration and 1) then XFlip endif Case 3 ' always flip XFlip End Select if (BehindDoor(GuestChoice) = Million) then GuestWins += 1 Endif ' GuestTrys += 1 Iteration += 1 wend print Iteration;" Iterations ", print " - Guest wins % ";(100*GuestWins)/Iteration Print "" print #1,Iteration;" Iterations ", print #1," - Guest wins % ";(100*GuestWins)/Iteration Print #1,"" Phase += 1 wend PRINT "All done!" PRINT #1,"All done!" Print "" print "Terminating BehindDoors, at ";date$,time$() Print "" Print #1,"" print #1,"Terminating BehindDoors, at ";date$,time$() Print #1,"" Close #1 print "press any key to terminate" WHILE INKEY$ = "": sleep (10):WEND END ' kills text screen

Started July 13, 2017

Last update July 13, 2017

Back to Nike Missile Home Page