When we did secret Santa a few years back I wrote a little python script similar to the below: import random l = ['Alice', 'Bob', 'Benny', 'Dolores'] random.shuffle(l) r = dict(zip(l, (l[(i + 1) % len(l)] for i in range(0, len(l))))) print(r) Basically just shuffle the list, assign everybody the one next on the list (with wrap around).
How to solve the Secret Santa Problem using graph theory
21–25 of 25 posts
Re: How to solve the Secret Santa Problem using graph theory
#22Re: How to solve the Secret Santa Problem using graph theory
#23I recall that in a general case finding a hamiltonian cycle (or path) is already NP-complete. Although it should be a simple problem for small real graphs, what article suggests, I think, is to use a brute-force solution. [1] https://mathworld.wolfram.com/HamiltonianPath.html
Re: How to solve the Secret Santa Problem using graph theory
#24One year my family did this when we were on vacation in a foreign country. I happened to have my laptop with me and wrote a shell script that would generate a random Secret Santa graph. Each family member would go up to my laptop, it would say, “Are you Alice?” they’d press enter, and the program would say, “You are assigned to Bob. Press enter.” They’d press enter and it would clear, ready for the next person.
Re: How to solve the Secret Santa Problem using graph theory
#25Every year, when my extended family (13 cousins) does Secret Santa, I complain “There are likely multiple cyclic graphs in this space!” But rather than engage my criticism with the mathematical rigor it clearly deserves, they just choose to restart with a random cousin who hasn’t given a gift yet when they discover the cycle. This is clearly a sub-optimal solution, and I am glad that when the ritual recurs next year,…