20 lines
447 B
Python
Executable File
20 lines
447 B
Python
Executable File
#!/usr/bin/env python3
|
|
import sys
|
|
import random
|
|
|
|
rng = random.SystemRandom()
|
|
|
|
def secret_santa(names):
|
|
"""Draw pairings for secret santa.
|
|
|
|
We recognize the problem as a random Hamiltonian cycle
|
|
on the complete graph formed by the set of names.
|
|
"""
|
|
g = list(names)
|
|
rng.shuffle(g)
|
|
return list(zip(g, g[1:] + g[:1]))
|
|
|
|
if __name__ == '__main__':
|
|
for pair in secret_santa(sys.argv[1:]):
|
|
print("%s -> %s" % pair)
|