Show HN: Secret Santa in python
github.com
github.com
Viewed like that, an "optimal" solution is brilliantly simple: given n names, shuffle the array of names, then assign person[k] to give to person[k+1], with the special case where k == n, person[k] gives to person[0].
The rest of the short implementation adds a `receive_from` property to each person which could be useful in QAing the implementation.
If you still need to assign Secret Santa givers, feel free to use my implementation!
It’s a surprisingly fun little problem
def santa_list(people):
return dict(zip(
people[1:] + people[:1],
people))
(shuffle if you want to).