Data update
This commit is contained in:
parent
796d366b97
commit
35bcdeebf8
504 changed files with 7045 additions and 610 deletions
21
Task/Monty-Hall-problem/Chapel/monty-hall-problem-2.chapel
Normal file
21
Task/Monty-Hall-problem/Chapel/monty-hall-problem-2.chapel
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
use Random;
|
||||
|
||||
config const numGames = 100_000_000;
|
||||
|
||||
var switch, stick: uint;
|
||||
|
||||
// have a separate RNG for each task; add together the results at the end
|
||||
forall i in 1..numGames
|
||||
with (var rand = new RandomStream(uint, parSafe = false), + reduce stick)
|
||||
{
|
||||
var chosen_door = rand.getNext() % 3;
|
||||
var winner_door = rand.getNext() % 3;
|
||||
if chosen_door == winner_door then
|
||||
stick += 1;
|
||||
}
|
||||
|
||||
// if you lost by sticking it means you would have won by switching
|
||||
switch = numGames - stick;
|
||||
writeln("Over ", numGames, " games:\n - switching wins ",
|
||||
100.0*switch / numGames, "% of the time and\n - sticking wins ",
|
||||
100.0*stick / numGames, "% of the time");
|
||||
Loading…
Add table
Add a link
Reference in a new issue