Skip to content

Instantly share code, notes, and snippets.

@jkotra
Created October 7, 2019 07:13
Show Gist options
  • Save jkotra/7760d1dd925bc3c72d5468811c31f056 to your computer and use it in GitHub Desktop.
Save jkotra/7760d1dd925bc3c72d5468811c31f056 to your computer and use it in GitHub Desktop.
n_doors = 3
n_siml = parsed_args["simulations"]
switch = parsed_args["switch"]
w = 0
l = 0
for i = 1:n_siml
doors = rand(0:0,n_doors)
#Keep the money in random door
money_door = rand(1:length(doors))
doors[money_door] = 1
chosen_door = rand(1:length(doors))
#DO YOU WANT TO SWITCH?!?!?!
if switch
doors_cpy = copy(doors)
doors_cpy[chosen_door] = -1
#open and mark money-less door!
host_choice = findall(x->x!=1 && x!=-1, doors_cpy)[1]
doors_cpy[host_choice] = -1
#set chosen door index
chosen_door = findall(x->x!=-1, doors_cpy)[1]
end
if doors[chosen_door] == 1
global w += 1
else
global l += 1
end
println("Chosen:",chosen_door," Money In:", money_door, " outcome:", doors[chosen_door] == 1)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment