Created
August 30, 2016 15:13
-
-
Save benjamincohen1/2090fd78d0cd6ffe18798b47fd73fc62 to your computer and use it in GitHub Desktop.
This file contains 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 random | |
STUDENTS = 16 | |
PROJECTS = 10 | |
STUDENTS_PER_PROJECT = 4 | |
def sim(): | |
all_students = range(STUDENTS) | |
worked_with = {x: set() for x in range(STUDENTS)} | |
for x in range(PROJECTS): | |
random.shuffle(all_students) | |
for group in range((STUDENTS//STUDENTS_PER_PROJECT)+1): | |
team = all_students[(group * STUDENTS_PER_PROJECT): ((group+1) * STUDENTS_PER_PROJECT)] | |
for member in team: | |
for partner in team: | |
worked_with[member].add(partner) | |
for student in worked_with: | |
if len(list(worked_with[student])) != STUDENTS: | |
return False | |
return True | |
def run_sims(n=100): | |
true, false = 0., 0. | |
for x in range(n): | |
if sim(): | |
true += 1 | |
else: | |
false += 1 | |
print "{} true, {} false, {} percent".format(true, false, (true/(true+false))) | |
run_sims(10000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment