Created
April 15, 2017 22:08
-
-
Save ShiangYong/59bc992fd66e4899e57dcc2e63cc1da4 to your computer and use it in GitHub Desktop.
Simulation code to solve the Riddler Classic puzzle (Supreme Court Judges),https://fivethirtyeight.com/features/how-many-bingo-cards-are-there-in-the-world/
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 numpy as np | |
def runSimulation(N): | |
judge_num = np.zeros(N, dtype=np.int) | |
for i in range(9): | |
judge_num[:(np.random.randint(0, 41))] += 1 | |
for i in range(4, N, 4): | |
if np.random.random() > 0.5: | |
# the same party has the presidency and congress so begin filling up the seat | |
while judge_num[i] < 9: | |
judge_num[i:i + (np.random.randint(0, 41))] += 1 | |
print(9 - np.mean(judge_num)) | |
# run main simulation | |
runSimulation(400*1000*1000) | |
runSimulation(400*1000*1000) | |
runSimulation(400*1000*1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected number of vacancies is 1.904