Skip to content

Instantly share code, notes, and snippets.

@ShiangYong
Created April 15, 2017 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShiangYong/59bc992fd66e4899e57dcc2e63cc1da4 to your computer and use it in GitHub Desktop.
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/
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)
@ShiangYong
Copy link
Author

Expected number of vacancies is 1.904

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment