
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.



Rules of the game

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 Hall 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?"



The question

Is it to your advantage to change your choice?



Note

The player may initially choose any of the three doors (not just Door 1), that the host opens a different door revealing a goat (not necessarily Door 3), and that he gives the player a second choice between the two remaining unopened doors.



Task

Run random simulations of the Monty Hall game. Show the effects of a strategy of the contestant always keeping his first guess so it can be contrasted with the strategy of the contestant always switching his guess.

Simulate at least a thousand games using three doors for each strategy and show the results in such a way as to make it easy to compare the effects of each strategy.



References

 Stefan Krauss, X. T. Wang, "The psychology of the Monty Hall problem: Discovering psychological mechanisms for solving a tenacious brain teaser.", Journal of Experimental Psychology: General, Vol 132(1), Mar 2003, 3-22 DOI: 10.1037/0096-3445.132.1.3
 A YouTube video:   Monty Hall Problem - Numberphile. 


       IDENTIFICATION DIVISION.
       PROGRAM-ID. monty-hall.
 
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       78  Num-Games               VALUE 1000000.
 
       *> These are needed so the values are passed to
       *> get-rand-int correctly.
       01  One                     PIC 9 VALUE 1.
       01  Three                   PIC 9 VALUE 3.
 
       01  doors-area.
           03  doors               PIC 9 OCCURS 3 TIMES.
 
       01  choice                  PIC 9.
       01  shown                   PIC 9.
       01  winner                  PIC 9.
 
       01  switch-wins             PIC 9(7).
       01  stay-wins               PIC 9(7).
 
       01  stay-wins-percent       PIC Z9.99.
       01  switch-wins-percent     PIC Z9.99.
 
       PROCEDURE DIVISION.
           PERFORM Num-Games TIMES
               MOVE 0 TO doors (winner)
 
               CALL "get-rand-int" USING CONTENT One, Three,
                   REFERENCE winner
               MOVE 1 TO doors (winner)
 
               CALL "get-rand-int" USING CONTENT One, Three,
                   REFERENCE choice
 
               PERFORM WITH TEST AFTER
                       UNTIL NOT(shown = winner OR choice)
                   CALL "get-rand-int" USING CONTENT One, Three,
                       REFERENCE shown
               END-PERFORM
 
               ADD doors (choice) TO stay-wins
               ADD doors (6 - choice - shown) TO switch-wins
           END-PERFORM
 
           COMPUTE stay-wins-percent ROUNDED =
               stay-wins / Num-Games * 100
           COMPUTE switch-wins-percent ROUNDED =
               switch-wins / Num-Games * 100
 
           DISPLAY "Staying wins   " stay-wins " times ("
               stay-wins-percent "%)."
           DISPLAY "Switching wins " switch-wins " times ("
               switch-wins-percent "%)."
           .
 
       IDENTIFICATION DIVISION.
       PROGRAM-ID. get-rand-int.
 
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  call-flag               PIC X VALUE "Y".
           88  first-call          VALUE "Y", FALSE "N".
 
       01  num-range               PIC 9.
 
       LINKAGE SECTION.
       01  min-num                 PIC 9.
       01  max-num                 PIC 9.
 
       01  ret                     PIC 9.
 
       PROCEDURE DIVISION USING min-num, max-num, ret.
           *> Seed RANDOM once.
           IF first-call
               MOVE FUNCTION RANDOM(FUNCTION CURRENT-DATE (9:8))
                   TO num-range
               SET first-call TO FALSE
           END-IF
 
           COMPUTE num-range = max-num - min-num + 1
           COMPUTE ret =
              FUNCTION MOD(FUNCTION RANDOM * 100000, num-range)
              + min-num
           .
       END PROGRAM get-rand-int.
 
       END PROGRAM monty-hall.