Created
October 7, 2019 07:16
-
-
Save jkotra/ae31cd57be48fd762fedf759f4458168 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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