Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save benjamincohen1/2090fd78d0cd6ffe18798b47fd73fc62 to your computer and use it in GitHub Desktop.
Save benjamincohen1/2090fd78d0cd6ffe18798b47fd73fc62 to your computer and use it in GitHub Desktop.
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