Created
October 25, 2019 12:47
-
-
Save antlauzon/5b0a3ad15498fe083e735834a11e745c to your computer and use it in GitHub Desktop.
monty hall
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
import random | |
ITERS = 10000 | |
a = ['g', 'g', 'c'] | |
stay_results = [] | |
for i in range(ITERS): | |
random.shuffle(a) | |
init_choice = int(random.random()*len(a)) | |
goat = [i for i in range(3) if i != init_choice and a[i] != 'c'][0] | |
if a[init_choice] == 'c': | |
stay_results.append(1) | |
else: | |
stay_results.append(0) | |
switch_results = [] | |
for i in range(ITERS): | |
random.shuffle(a) | |
init_choice = int(random.random()*len(a)) | |
goat = [i for i in range(3) if i != init_choice and a[i] != 'c'][0] | |
switch = list(set([0,1,2]) - set([init_choice, goat]))[0] | |
if a[switch] == 'c': | |
switch_results.append(1) | |
else: | |
switch_results.append(0) | |
print("SWITCH: {}".format(sum(switch_results)/ITERS)) | |
print("STAY: {}".format(sum(stay_results)/ITERS)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment