Created
February 27, 2016 16:58
-
-
Save ztane/918d1a3c64f91c222bfe to your computer and use it in GitHub Desktop.
50/50 simulation of WWTBAM
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
% python3 millionaire.py | |
Out of 1000000 cases | |
Initial was eliminated in 499869 cases (49.9869 %) | |
Initial was not eliminated in 500131 cases (50.0131 %) | |
There answer was different from initial in 249818 cases | |
Thus changing is winning 49.95051296560301 % if initial was not eliminated |
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
#!/usr/bin/python3 | |
import random | |
N = 1000000 | |
initial_eliminated = 0 | |
initial_not_eliminated = 0 | |
wins_for_change = 0 | |
for i in range(N): | |
# 1 answer among 'ABCD' is correct | |
answer = random.choice('ABCD') | |
# initial answer is also chosen at random | |
initial = random.choice('ABCD') | |
# the wrong answers are thus the set of all answers | |
# less the correct answer. | |
wrong = set('ABCD') - set(answer) | |
# we choose 1 of these wrong answers at random | |
# to remain alongside with the right answer | |
wrong_after_elimination = random.choice(list(wrong)) | |
# if initial is among correct answer and "wrong-after elimination" | |
if initial in [answer, wrong_after_elimination]: | |
initial_not_eliminated += 1 | |
# if initial is *not* the answer, then increase wins for change | |
if initial != answer: | |
wins_for_change += 1 | |
# eles initial answer was just eliminated. | |
else: | |
initial_eliminated += 1 | |
print('Out of {} cases'.format(N)) | |
print('Initial was eliminated in {} cases ({} %)' | |
.format(initial_eliminated, 100 * initial_eliminated / N)) | |
print('Initial was not eliminated in {} cases ({} %)' | |
.format(initial_not_eliminated, 100 * initial_not_eliminated / N)) | |
print('There answer was different from initial in {} cases' | |
.format(wins_for_change)) | |
print('Thus changing is winning {} % if initial was not eliminated' | |
.format(100 * wins_for_change / initial_not_eliminated)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment