Created
July 4, 2021 14:04
-
-
Save Shikugawa/de9f55b0da697d764081d15a2821792c 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
import random | |
doors = [True, False, False] | |
def get_false(): | |
s = [] | |
for i, d in enumerate(doors): | |
if not d: | |
s.append(i) | |
return s | |
def get_true(): | |
s = [] | |
for i, d in enumerate(doors): | |
if d: | |
return i | |
cnt = 0 | |
for i in range(0, 100000): | |
random.shuffle(doors) | |
s = random.randint(0, 2) | |
while True: | |
m = random.randint(0, 1) | |
m = get_false()[m] | |
if m != s: | |
break | |
for i in range(0, 3): | |
if i != s and i != m: | |
s = i | |
break | |
if s == get_true(): | |
cnt += 1 | |
print(cnt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment