Secret santa script

This commit is contained in:
Michael Soukup 2025-11-08 18:09:40 +01:00
commit 7ffedd972a
2 changed files with 31 additions and 0 deletions

12
README.md Normal file
View File

@ -0,0 +1,12 @@
# Secret Santa
Example usage:
```
$ ./secret-santa.py Elsa Anna Kristoffer Svein Olaf
Svein -> Elsa
Elsa -> Olaf
Olaf -> Kristoffer
Kristoffer -> Anna
Anna -> Svein
```

19
secret-santa.py Executable file
View File

@ -0,0 +1,19 @@
#!/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)