31 lines
1 KiB
Text
31 lines
1 KiB
Text
def Games = 10000; \number of games simulated
|
|
int Game, Wins;
|
|
include c:\cxpl\codes;
|
|
|
|
proc Play(Switch); \Play one game
|
|
int Switch;
|
|
int Car, Player, Player0, Monty;
|
|
[Car:= Ran(3); \randomly place car behind a door
|
|
Player0:= Ran(3); \player randomly chooses a door
|
|
repeat Monty:= Ran(3); \Monty opens door revealing a goat
|
|
until Monty # Car and Monty # Player0;
|
|
if Switch then \player switches to remaining door
|
|
repeat Player:= Ran(3);
|
|
until Player # Player0 and Player # Monty
|
|
else Player:= Player0; \player sticks with original door
|
|
if Player = Car then Wins:= Wins+1;
|
|
];
|
|
|
|
[Format(2,1);
|
|
Text(0, "Not switching doors wins car in ");
|
|
Wins:= 0;
|
|
for Game:= 0 to Games-1 do Play(false);
|
|
RlOut(0, float(Wins)/float(Games)*100.0);
|
|
Text(0, "% of games.^M^J");
|
|
|
|
Text(0, "But switching doors wins car in ");
|
|
Wins:= 0;
|
|
for Game:= 0 to Games-1 do Play(true);
|
|
RlOut(0, float(Wins)/float(Games)*100.0);
|
|
Text(0, "% of games.^M^J");
|
|
]
|