29 lines
747 B
Text
29 lines
747 B
Text
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)].
|