Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Monty-Hall-problem/XPL0/monty-hall-problem.xpl0
Normal file
31
Task/Monty-Hall-problem/XPL0/monty-hall-problem.xpl0
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
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");
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue