Retrocomputing

Monty Hall 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. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice? The chance should be 50/50 no matter what you do, right?

You can now try both strategies by playing this game in Microsoft BASIC. Wikipedia has more information about the Monty Hall problem.

The Monty Hall problem as a game

10 PRINT "THIS IS A GUESSING GAME"
20 PRINT "THERE ARE 3 DOORS AND A PRIZE BEHIND ONE OF THEM."
30 PRINT "CHOOSE A DOOR. ONE OF THE OTHER DOORS WILL BE OPENED."
40 PRINT "YOU CAN THEN CHANGE YOUR GUESS"
100 W=0:R=0
105 DIM D(3,3)
110 GOSUB 1000
130 P = INT(RND(1)*3)+1
160 INPUT "YOUR GUESS";G
170 IF G < 4 AND G > 0 AND G=INT(G) THEN 200
180 PRINT "YOUR GUESS MUST BE 1, 2 OR 3."
190 GOTO 160
200 REM OPEN DOOR WITH NO PRIZE
210 O = D(G,P)
230 IF O <> 0 THEN 300
240 O = INT(RND(1)*2)+P+1
250 IF O > 3 THEN O=O-3
300 PRINT "OPENING DOOR";O
310 REM SWITCH
320 INPUT "DO YOU WANT TO SWITCH TO THE OTHER DOOR";A$
330 IF LEFT$(A$,1) <> "Y" THEN 400
340 G=D(O,G)
350 PRINT "SWITCHING TO";G
400 PRINT "PRIZE WAS BEHIND DOOR";P;
420 IF G<>P THEN 500
430 W=W+1
440 PRINT "-- YOU WIN"
450 GOTO 510
500 PRINT "-- YOU LOOSE"
510 R=R+1
520 INPUT "TRY AGAIN";A$
530 IF LEFT$(A$,1) = "Y" THEN 130
540 PRINT "YOU HAD";W;"WINS IN";R;"RUNS"
550 PRINT "THAT IS";W/R*100;"%"
999 END
1000 REM INITIALIZE MATRIX
1010 FOR J = 1 TO 3
1020 FOR I = 1 TO 3
1030 READ D(J,I)
1040 NEXT I
1050 NEXT J
1060 RETURN
1070 DATA 0,3,2, 3,0,1, 2,1,0

Simulation

If you are impatient, then you can run a simulation of 100 random guesses and see for yourself.

10 PRINT "SIMULATES 100 GUESSES AND SUMS UP THE WINS"
20 INPUT "DO YOU WANT TO SWITCH DOOR";A$
30 A$=LEFT$(A$,1)
100 W=0
110 DIM D(3,3)
120 GOSUB 1000
130 FOR R = 1 TO 100
140   P = INT(RND(1)*3)+1
150   PRINT "PRIZE IS BEHIND DOOR";P;
160   G = INT(RND(1)*3)+1
170   PRINT "YOUR GUESS";G;
200   REM OPEN DOOR NO PRIZE
210   O = D(G,P)
230   IF O <> 0 THEN 300
240   O = INT(RND(1)*2)+P+1
250   IF O > 3 THEN O=O-3
300   PRINT "OPENING DOOR";O;
310   REM SWITCH
320   IF A$ <> "Y" THEN 420
330   G=D(O,G)
340   PRINT "SWITCHING TO";G;
420   IF G<>P THEN 500
430   W=W+1
440   PRINT "WIN";
500   PRINT
520 NEXT R
530 PRINT "WINS:",W
999 END
1000 REM INITIALIZE DECISION MATRIX
1010 FOR J = 1 TO 3
1020 FOR I = 1 TO 3
1030 READ D(J,I)
1040 NEXT I
1050 NEXT J
1060 RETURN
1070 DATA 0,3,2, 3,0,1, 2,1,0