Skip to content

Instantly share code, notes, and snippets.

@cjwinchester
Last active November 20, 2019 01:39
Show Gist options
  • Save cjwinchester/0642cfeb4ea8870b9e95f2ed62752759 to your computer and use it in GitHub Desktop.
Save cjwinchester/0642cfeb4ea8870b9e95f2ed62752759 to your computer and use it in GitHub Desktop.
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