Softcode Problem: Naughty List

Submitted by walker on Fri, 2011-12-30 00:07

For the past few years, I've been running a Secret Santa on M*U*S*H. But with such a small pool of attendees, we're now having an "issue" where one person might have the same recipient or gifter several times in a row. "Walker again? I gave him a gift last year and the year before that!"

(Okay, so maybe everybody has Walker, but that's a different topic . . . =)

After everybody has +santa/join'd, I assign santas by shuffle()-ing the list. Everybody has the _next_ person in the list (with last winding back to first). So if Alice, Bob, Charlie, Dave, Edna and Frank join secret santa, then a shuffle() might get:

Charlie Dave Alice Edna Frank Bob

Charlie gives Dave a gift, who gives Alice a gift, and so on to Bob, who gives Charlie a gift.

Then the next year, maybe Charlie gets Dave again, but everybody else is different. So Charlie wants to avoid giving Dave another gift.

So here's a challenge: +santa/naughty - Means you don't want to give a gift. (They can still give _you_ a gift, unless they +santa/naughty you!)

Now, there's an obvious solution: shuffle(), check to make sure there's no giver->naughty pairs. If there is, repeat. That's an ugly, brute force solution.

So now here's a softcode challenge for you! (Also, because CPO needs some life blown into it!) - Create a solution that is _not_ brute force!