RosettaCodeData/Task/Monty-Hall-problem/Zkl/monty-hall-problem.zkl
2017-09-25 22:28:19 +02:00

17 lines
584 B
Text

const games=0d100_000;
reg switcherWins=0, keeperWins=0, shown=0;
do(games){
doors := L(0,0,0);
doors[(0).random(3)] = 1; // Set which one has the car
choice := (0).random(3); // Choose a door
while(1){ shown = (0).random(3);
if (not (shown == choice or doors[shown] == 1)) break; }
switcherWins += doors[3 - choice - shown];
keeperWins += doors[choice];
}
"Switcher Wins: %,d (%3.2f%%)".fmt(
switcherWins, switcherWins.toFloat() / games * 100).println();
"Keeper Wins: %,d (%3.2f%%)".fmt(
keeperWins, keeperWins.toFloat() / games * 100).println();