forked from quantslob/monty_hall_simulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim.jl
30 lines (21 loc) · 882 Bytes
/
sim.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using StatsBase;
n = 3; # number of doors
r = 1; # number of losing doors revealed by host, must be > 0 AND < n - 1
nn = 10000; # total number of simulations
os_wins = falses(1, nn);
sw_wins = falses(1, nn);
d_space = [1:1:3;];
kk = 0;
while kk < nn
global kk += 1;
door_prize = sample(d_space);
door_select = sample(d_space);
doors_can_reveal = setdiff(d_space, [door_prize, door_select]);
doors_revealed = doors_can_reveal[sample([1:1:length(doors_can_reveal);], r)];
doors_can_switch = setdiff(d_space, [door_select, first(doors_revealed)]);
door_switch = doors_can_switch[sample([1:1:length(doors_can_switch);])];
os_wins[kk] = door_prize == door_select;
sw_wins[kk] = door_prize == door_switch;
end
print("proportion original selection wins: ", sum(os_wins) / nn, "\n")
print("proportion switching wins: ", sum(sw_wins) / nn, "\n")