Monty Hall problem: Difference between revisions

(→‎{{header|Prolog}}: Adding Prolog)
Line 3,250:
Output:
<pre>Iterations: 10000 - Stayed wins: 3331 (33.31%) - Switched wins: 6669 (66.69%)</pre>
 
=={{header|Picat}}==
<lang Picat>go =>
_ = random2(), % different seed
member(Rounds,[1000,10_000,100_000,1_000_000,10_000_000]),
println(rounds=Rounds),
SwitchWins = 0,
StayWins = 0,
NumDoors = 3,
foreach(_ in 1..Rounds)
Winner = choice(NumDoors),
Choice = choice(NumDoors),
% Shown is not needed for the simulation
% Shown = pick([Door : Door in 1..NumDoors, Door != Winner, Door != Choice]),
if Choice == Winner then
StayWins := StayWins + 1
else
SwitchWins := SwitchWins + 1
end
end,
 
printf("Switch win ratio %0.5f%%\n", 100.0 * SwitchWins/Rounds),
printf("Stay win ratio %0.5f%%\n", 100.0 * StayWins/Rounds),
nl,
fail,
nl.
 
% pick a number from 1..N
choice(N) = random(1,N).
 
pick(L) = L[random(1,L.len)].</lang>
 
Output:
<pre>rounds = 1000
Switch win ratio 68.80000%
Stay win ratio 31.20000%
 
rounds = 10000
Switch win ratio 67.25000%
Stay win ratio 32.75000%
 
rounds = 100000
Switch win ratio 66.69700%
Stay win ratio 33.30300%
 
rounds = 1000000
Switch win ratio 66.65520%
Stay win ratio 33.34480%
 
rounds = 10000000
Switch win ratio 66.66641%
Stay win ratio 33.33359%</pre>
 
 
=={{header|PicoLisp}}==
495

edits