Monty Hall problem: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl 6}}: added .race for concurrency, then 10_000 trials isn't too slow)
Line 2,651: Line 2,651:


=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{works with|rakudo|2015-09-24}}
{{works with|Rakudo|2018.09}}
This implementation is parametric over the number of doors. [[wp:Monty_Hall_problem#Increasing_the_number_of_doors|Increasing the number of doors in play makes the superiority of the switch strategy even more obvious]].
This implementation is parametric over the number of doors. [[wp:Monty_Hall_problem#Increasing_the_number_of_doors|Increasing the number of doors in play makes the superiority of the switch strategy even more obvious]].


Line 2,679: Line 2,679:
}
}
constant TRIALS = 1000;
constant TRIALS = 10_000;
for 3, 10 -> $doors {
for 3, 10 -> $doors {
Line 2,685: Line 2,685:
say "With $doors doors: ";
say "With $doors doors: ";
for Stay, 'Staying', Switch, 'Switching' -> $s, $name {
for Stay, 'Staying', Switch, 'Switching' -> $s, $name {
for ^TRIALS {
(^TRIALS).race.map: {
++%wins{$s} if play($s, doors => $doors) == Car;
++%wins{$s} if play($s, doors => $doors) == Car;
}
}
Line 2,695: Line 2,695:
{{out}}
{{out}}
<pre>With 3 doors:
<pre>With 3 doors:
Staying wins 31% of the time.
Staying wins 34% of the time.
Switching wins 68% of the time.
Switching wins 66% of the time.
With 10 doors:
With 10 doors:
Staying wins 9% of the time.
Staying wins 10% of the time.
Switching wins 90% of the time.</pre>
Switching wins 90% of the time.</pre>