Monty Hall problem: Difference between revisions

No edit summary
Line 263:
<pre>Switching wins 21924 times.
Staying wins 10844 times.</pre>
 
=={{header|MAXScript}}==
<pre>
fn montyHall choice switch =
(
doors = #(false, false, false)
doors[random 1 3] = true
chosen = doors[choice]
if switch then chosen = not chosen
chosen
)
 
fn iterate iterations switched =
(
wins = 0
for i in 1 to iterations do
(
if (montyHall (random 1 3) switched) then
(
wins += 1
)
)
wins * 100 / iterations as float
)
 
iterations = 10000
format ("Stay strategy:%\%\n") (iterate iterations false)
format ("Switch strategy:%\%\n") (iterate iterations true)
</pre>
Output:
<pre>Stay strategy:33.77%
Switch strategy:66.84%</pre>
 
=={{header|OCaml}}==
Anonymous user