Last active
November 20, 2019 01:39
-
-
Save cjwinchester/0642cfeb4ea8870b9e95f2ed62752759 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
from random import sample | |
from itertools import chain | |
FAMILIES = { | |
'Joel and Amanda Sletten': ['Blaine', 'Bruce', 'Titus', 'Olivia'], | |
'Micah and Leslie Winchester': ['Jack', 'Alex'], | |
'Cody and Laurel Winchester': ['Julian', 'Lucy'], | |
'Barry and April Winchester': ['Brook', 'Blake'] | |
} | |
KIDS = list(chain.from_iterable(FAMILIES.values())) | |
def make_matches(): | |
final = {} | |
taken = [] | |
try: | |
for f in FAMILIES: | |
opk = [x for x in KIDS if x not in FAMILIES[f] and x not in taken] | |
picks = sample(opk, len(FAMILIES[f])) | |
final[f] = picks | |
taken.extend(picks) | |
return final | |
except ValueError: | |
return | |
while True: | |
matches = make_matches() | |
if matches: | |
for m in matches: | |
print(m, '=>', ', '.join(matches[m])) | |
break | |
else: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment