Last active
December 18, 2016 07:39
-
-
Save ciela/a4a9e66cfa1563135c58478ace5198a3 to your computer and use it in GitHub Desktop.
モンティホール問題シミューレション
This file contains 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/env python3 | |
# coding: utf-8 | |
import numpy as np | |
NUM = 100000 # 試行回数 | |
DOORS = np.array([1, 2, 3]) # ドア | |
# 変更しない場合 | |
succeeded = 0 | |
for i in range(NUM): | |
car = np.random.choice(DOORS) | |
selected = np.random.choice(DOORS) | |
if selected == car: | |
succeeded += 1 | |
print('No change: ', str(succeeded/NUM)) | |
# 変更した場合 | |
succeeded = 0 | |
for i in range(NUM): | |
car = np.random.choice(DOORS) | |
selected = np.random.choice(DOORS) | |
goat = np.random.choice(DOORS[(DOORS != car) & (DOORS != selected)]) | |
selected = np.random.choice(DOORS[(DOORS != goat) & (DOORS != selected)]) | |
if selected == car: | |
succeeded += 1 | |
print('Change: ', str(succeeded/NUM)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment