Last active
December 5, 2018 12:30
-
-
Save Da-Juan/6f8b26c165d2c2c381b8b8384d04180c to your computer and use it in GitHub Desktop.
Radomize secret santa pairings
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/python3 | |
import random | |
people = [ | |
"Foo", | |
"Bar", | |
"Baz", | |
"Qux", | |
"Quux", | |
"Corge", | |
"Grault", | |
"Garply", | |
"Waldo", | |
"Fred", | |
"Plugh", | |
"Xyzzy", | |
"Thud", | |
] | |
def valid(a, b): | |
for i, j in zip(a, b): | |
if i == j: | |
return False | |
return True | |
givers = list(people) | |
recipients = list(people) | |
while not valid(givers, recipients): | |
random.shuffle(givers) | |
random.shuffle(recipients) | |
# sort pairings alphabetically with case insensitive | |
pairings = sorted( | |
list(zip(givers, recipients)), | |
key=lambda tup: tup[0].casefold() | |
) | |
for p in pairings: | |
print('%s -> %s' % (p[0], p[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment