Skip to content

Instantly share code, notes, and snippets.

@itdxer
Created May 21, 2020 15:31
Show Gist options
  • Save itdxer/a9556e09a2c5ee1e0c9226419d79eb80 to your computer and use it in GitHub Desktop.
Save itdxer/a9556e09a2c5ee1e0c9226419d79eb80 to your computer and use it in GitHub Desktop.
import numpy as np
n_rolls = 10000000
n_sides = 20
min_dice_value = 8
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("simulation:", np.mean(np.maximum(rolls_1.min(axis=1), rolls_2.min(axis=1))
>= min_dice_value))
print('-' * 30)
print('disadvantage of advantages')
print("simulation:", np.mean(np.minimum(rolls_1.max(axis=1), rolls_2.max(axis=1))
>= min_dice_value))
print('-' * 30)
print('single roll')
print("simulation:", np.mean(rolls_1[:, 0] >= min_dice_value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment