Skip to content

Instantly share code, notes, and snippets.

@molokov
Created September 16, 2015 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save molokov/90d30d211aeccacaf58c to your computer and use it in GitHub Desktop.
Save molokov/90d30d211aeccacaf58c to your computer and use it in GitHub Desktop.
Geek & Sundry Secret Santa
#!/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