Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Monty-Hall-problem/Picat/monty-hall-problem.picat
Normal file
29
Task/Monty-Hall-problem/Picat/monty-hall-problem.picat
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
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)].
|
||||
Loading…
Add table
Add a link
Reference in a new issue