Created
June 27, 2016 16:29
-
-
Save ehermes/b5945f836c49b9dc156c25773d3d0151 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
| #!/usr/bin/env python | |
| from random import shuffle | |
| import numpy as np | |
| nb = 2 # Number of Bruna's in deck | |
| ng = 3 # Number of Gisela's in deck | |
| ncards = 60 # Total number of cards in deck | |
| # Construct the deck | |
| deck = ['b' for i in range(nb)] | |
| deck.extend(['g' for i in range(ng)]) | |
| deck.extend(['l' for i in range(ncards - nb - ng)]) | |
| ndraws = np.zeros(ncards, dtype=int) | |
| # Shuffle it | |
| for n in range(10000): | |
| found_b = False | |
| found_g = False | |
| shuffle(deck) | |
| for i, c in enumerate(deck): | |
| if c == 'b': | |
| found_b = True | |
| elif c == 'g': | |
| found_g = True | |
| if found_b and found_g: | |
| ndraws[i] += 1 | |
| break | |
| prob = np.array(ndraws, dtype=float) / float(np.sum(ndraws)) | |
| print(np.cumsum(prob)) |
Author
Author
Output for nb = 4 and ng = 4:
[ 0. 0.0086 0.027 0.0483 0.0761 0.1084 0.1445 0.1819 0.2235
0.2662 0.306 0.3489 0.386 0.4295 0.4704 0.5122 0.5484 0.5837
0.6155 0.654 0.6845 0.7172 0.747 0.7704 0.7961 0.8164 0.8363
0.8546 0.8721 0.8857 0.9024 0.9155 0.9275 0.9381 0.9471 0.9546
0.9606 0.9674 0.9728 0.9777 0.9825 0.9865 0.9893 0.9922 0.9946
0.9958 0.9969 0.9981 0.9987 0.9991 0.9994 0.9995 0.9999 1. 1.
1. 1. 1. 1. 1. ]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output for
nb = 2andng = 3: