Jump to content

Monty Hall problem: Difference between revisions

→‎{{header|XPL0}}: The procedure Play replaced by a pure function.
(→‎{{header|XPL0}}: The procedure Play replaced by a pure function.)
Line 5,161:
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">def GamesNGames = 10000; \number of games simulated
int Game, WinsNWins;
include c:\cxpl\codes;
 
procfunc Playint IsGameWon(Switch); \Play one game
int Switch;
int Car, Player, Player0, Monty;
Line 5,176:
until Player # Player0 and Player # Monty
else Player:= Player0; \player sticks with original door
ifreturn Player = Car then Wins:= Wins+1;
];
 
[Format(2,1);
Text(0, "NotNOT switching doors wins car in ");
WinsNWins:= 0;
for Game:= 0 to GamesNGames-1 do Play(false);
if IsGameWon(false) then NWins:= NWins+1;
RlOut(0, float(WinsNWins)/float(GamesNGames)*100.0);
Text(0, "% of games.^M^J");
 
Text(0, "But switching doors wins car in ");
WinsNWins:= 0;
for Game:= 0 to GamesNGames-1 do Play(true);
if IsGameWon(true) then NWins:= NWins+1;
RlOut(0, float(WinsNWins)/float(GamesNGames)*100.0);
Text(0, "% of games.^M^J");
]</syntaxhighlight>
Line 5,195 ⟶ 5,197:
Example output:
<pre>
NotNOT switching doors wins car in 33.7% of games.
But switching doors wins car in 66.7% of games.
</pre>
 
 
=={{header|Yabasic}}==
511

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.