Skip to content

Instantly share code, notes, and snippets.

@rcloran
Created April 8, 2013 23:15
Show Gist options
  • Save rcloran/5341397 to your computer and use it in GitHub Desktop.
Save rcloran/5341397 to your computer and use it in GitHub Desktop.
import random
RUNS = 10**3
APPLICANTS = 124000
ACCEPTED_1 = 20000
ACCEPTED_2 = 65000
FRIENDS = 4
def do_run():
batch = range(APPLICANTS)
random.shuffle(batch)
while any(x < FRIENDS for x in batch[:ACCEPTED_1]):
random.shuffle(batch)
return sum(x < FRIENDS for x in batch[ACCEPTED_1:ACCEPTED_2])
if __name__ == '__main__':
selected = [0] * (FRIENDS + 1)
for run in xrange(RUNS):
if run % 1000:
print 'Done %s runs' % (run, )
num_selected = do_run()
selected[num_selected] += 1
print 'After %s runs,' % (RUNS, )
for i, n in enumerate(selected):
print '%s people were selected %s times' % (i, n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment