-
Notifications
You must be signed in to change notification settings - Fork 14
Secret Santa
This was a really fun problem that I'd tackled in December while building a tiny web app which took your name and returned the name of the person for whom you should buy a gift.
One of the design goals was that I couldn't know who was giving me a gift, so I couldn't just hard code a solution. It also needed to be consistent for everyone using it, so it couldn't give out names at random.
With no constraints this problem is pretty simple: you start with a gifter, associate a giftee, remove the giftee from circulation and continue. The computer version of picking from a hat.
It gets a lot more interesting once constraints pop up. "No spouses" is one we imposed on our secret santa circle, but you can also say "not the same person you gave to last year" or "no boss-subordinate gifts" or whatever.
Solving that in a performant fashion turns out to be a really interesting problem, and people had a lot of fun working on this one. I might bring it back again in November (global day is in December) as an early holiday themed problem.
One pair posted their solution here: https://github.com/pbevin/TorontoCodeRetreat/blob/master/santa.c