Created
September 16, 2015 22:57
-
-
Save molokov/90d30d211aeccacaf58c to your computer and use it in GitHub Desktop.
Geek & Sundry Secret Santa
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
#!/usr/bin/env python | |
import copy | |
import random | |
import pprint | |
nice_list = [ | |
# People's names/usernames go here | |
] | |
recipients = copy.deepcopy(nice_list) | |
matches = {} | |
count = 0 | |
while set(matches.keys()) != set(nice_list) and count < 10: | |
# Check it twice... | |
for santa in nice_list + nice_list: | |
if santa in matches: | |
# Already assigned | |
continue | |
santee = random.choice(recipients) | |
if santee == santa: | |
# Can't send to yourself | |
continue | |
if santee in matches and matches[santee] == santa: | |
# Don't want santa & santee sending to each other | |
continue | |
matches[santa] = santee | |
recipients.remove(santee) | |
# Completed first iteration... | |
if set(matches.keys()) != set(nice_list): | |
print "missing = ", [n for n in nice_list if n not in matches.keys()] | |
else: | |
print "COMPLETE!" | |
count += 1 | |
pprint.pprint(matches) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment