Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
29
Task/Monty-Hall-problem/SETL/monty-hall-problem.setl
Normal file
29
Task/Monty-Hall-problem/SETL/monty-hall-problem.setl
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
program monty_hall;
|
||||
setrandom(0);
|
||||
|
||||
n_simulations := 100000;
|
||||
print('Chance to win:');
|
||||
print('When switching doors:', win_chance(true, n_simulations) * 100, '%');
|
||||
print('When not switching doors:', win_chance(false, n_simulations) * 100, '%');
|
||||
|
||||
proc win_chance(switch, n_simulations);
|
||||
wins := 0;
|
||||
loop for i in [1..n_simulations] do
|
||||
wins +:= if simulate(switch) then 1 else 0 end;
|
||||
end loop;
|
||||
return wins / n_simulations;
|
||||
end proc;
|
||||
|
||||
proc simulate(switch);
|
||||
doors := {1, 2, 3};
|
||||
car := random doors;
|
||||
goats := doors less car;
|
||||
choice := random doors;
|
||||
opened := random (goats less choice);
|
||||
|
||||
if switch then
|
||||
choice := arb (doors less choice less opened);
|
||||
end if;
|
||||
return choice = car;
|
||||
end proc;
|
||||
end program;
|
||||
Loading…
Add table
Add a link
Reference in a new issue