Created
May 21, 2020 15:23
-
-
Save itdxer/8a5d073965abaeb0a3bc2cab3b9951fc 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
import numpy as np | |
n_rolls = 10000000 | |
n_sides = 20 | |
rolls_1 = np.random.randint(n_sides, size=(n_rolls, 2)) + 1 | |
rolls_2 = np.random.randint(n_sides, size=(n_rolls, 2)) + 1 | |
print('-' * 30) | |
print('advantage of disadvantages') | |
print("expected: ", (2 * n_sides ** 2 - 1) / n_sides ** 4) | |
print("simulation:", np.mean(np.maximum(rolls_1.min(axis=1), rolls_2.min(axis=1)) | |
== n_sides)) | |
print('-' * 30) | |
print('disadvantage of advantages') | |
print("expected: ", ((2 * n_sides - 1) / n_sides ** 2) ** 2) | |
print("simulation:", np.mean(np.minimum(rolls_1.max(axis=1), rolls_2.max(axis=1)) | |
== n_sides)) | |
print('-' * 30) | |
print('single roll') | |
print("expected: ", 1 / n_sides) | |
print("simulation:", np.mean(rolls_1[:, 0] == n_sides)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment