# Secret santa problem

We decided to do secret Santa in our office. And this brought up a whole heap of problems that nobody could think of solutions for - bear with me here.. this is an important problem.

We have 4 people in our office - each with a partner that will be at our Christmas meal.

Steve, Christine, Mark, Mary, Ken, Ann, Paul(me), Vicki

Desired outcome

Nobody can know who is buying a present for anybody else. But we each want to know who we are buying our present for before going to the Christmas party. And we don't want to be buying presents for our partners. Partners are not in the office.

Obvious solution is to put all the names in the hat - go around the office and draw two cards.

And yes - sure enough I drew myself and Mark drew his partner. (we swapped)

With that information I could work out that Steve had a 1/3 chance of having Vicki(he didn't have himself or Christine - nor the two cards I had acquired Ann or Mary) and I knew that Mark was buying my present. Unacceptable result.

Ken asked the question: "What are the chances that we will pick ourselves or our partner?"

So I had a stab at working that out.

First card drawn -> 2/8 Second card drawn -> 12/56

Adding them together makes 28/56 i.e. 1/2.

i.e. This method won't ever work... half chances of drawing somebody you know means we'll be drawing all year before we get a solution that works.

My first thought was that we attach two cards to our backs... put on blindfolds and stumble around in the dark grabbing the first cards we came across... However this is a little unpractical and I'm pretty certain we'd end up knowing who grabbed what anyway.

Does anybody have a solution for distributing cards that results in our desired outcome?

I'd prefer a solution without a third party..

-
I would probably just write a python script that shuffles the names randomly, and rejects the result if one of the forbidden combinations come up, and have it automatically e-mail the people with who they are buying for. (When your time is expensive, make the computer do it.) :) –  Willie Wong Nov 25 '11 at 9:51
Good point.. a third party (like a computer) is a good solution. –  Paul Hutchinson Nov 25 '11 at 9:55
-1, the setup is unclear: The question seems to switch back and forth between whether each person is choosing one name or two; the intent of "[p]artners are not in the office" is unclear (is that part of the "[d]esired outcome"? you want them fired?). (Incidentally, $14+12\ne28$.) –  msh210 Nov 25 '11 at 17:23

1) You could have a third party party handle the distribution of cards in the hat so that every draw will be valid.

And after each draw the third party will remove invalid cards and put valid ones for the next draw. That should happen without any of the participants knowledge of how much cards are placed and removed.

The downside is that you will have that person know (or at least have enough information to deduce it) about who draws who.

2) Another solution would be if you take 8 cards with each persons name on one side and then every pair makes a unique mark on the other side and puts them in envelopes.

Then you shuffle the envelops, put the cards on the table unique mark up and everyone draws in sequence. In this way you could distinguish the invalid choice without knowing who's who.

3) A modification of the above idea. Use cards with names, then every couple puts the in unique marked box (or envelopes) and then in a bigger box identical to the other ones.

Then someone puts the boxes in one of the offices, opens the big boxes and choses one card from one of the small boxes. Then everyone goes in one by one.

If no one looks at his own box no one knows if he/she was drawn or not.

UPDATE There is a chance that this scheme will fail if the last pair have less then 2 valid choices.

UPDATE If you have people enter the room randomly and without knowing the order of entrance that will solve the problem. That could be done (without third party) if you have one of the participants pick people at random to go there and then taking the last one.

This I hope works just as needed. :)

On a side Note : I would go for the script - it's easier, but organizing all of the above might be a lot of fun to all.

UPDATE Well the stared look of someone looking at you will be the hint no algorithm can deal with.

-
I like the idea of 2) in that it removes the need for a third party. It would require a modification of covering your eyes until it is your turn to draw. It does suffer from the same problem as Daniel's solution, in that when you're down to the last two people they have a 50% chance of having themselves or their partner left on the table and knowing who's buying their gift. To avoid this a solution that requires you to know which cards are yours can only be solved by everybody drawing at once - which means you know who's buying your present. Nice idea but it doesn't work :(. –  Paul Hutchinson Nov 25 '11 at 10:49
2) helped me come up with the solution. But I don't have the rep to answer my own question for 8 hours.. basically leave cards in your office.. move to your left through each office and choose to take or not take a card till you're at the last office.. take any cards that remain and you're the secret postman for those remaining cards (find somebody with to few cards). Solved! –  Paul Hutchinson Nov 25 '11 at 11:20
3) is the best by far I've heard... it beats my solution! (now I just need a way to market this idea! - I'm thinking wineboxes with wrapping paper! :D. –  Paul Hutchinson Nov 25 '11 at 13:40
There is a problem with (3) (or maybe I failed to understand you). Let us say that the people are {{1,2},{3,4},{5,6},{7,8}}. Suppose the following happened: 1 drew 4, 2 drew 5, 3 drew 1, 4 drew 6, 5 drew 3, 6 drew 2. Then 7 and 8 will find all three available boxes empty. Or suppose the following happened: 1 drew 4, and then 5 enters the room, opens the box, and finds one name already missing from the pair {3,4}. Then he gains information. –  Willie Wong Nov 25 '11 at 14:15
The first remark is true. There's a chance of this happening. I can't calculate it now but I suppose that it is lower than the all random one. About the second one. Well what information does he gain ? Someone (1,2,3,4, ,6,7,8 (if sequential remove 6,7,8)) drew someone else (1,2,3,4, , ,7,8). The one exploit I could see is if the second to enter draws from the same box the first drew, or sees that he (or his partner) is drawn by 1. If you have everyone choose random box, random draw (repeat if empty) and look at nothing else then there is a low chance that anyone would get enough info. –  Dimitar Slavchev Nov 25 '11 at 16:38

If each of you just draws a random name out of the hat, the probability that nobody gets their own or their partner's name is

$$\frac{4752}{40320} = \frac{33}{280} \approx 11.8\%.$$

Thus, the expected number of times you'll need to repeat the process before getting "a solution that works" is $280/33 \approx 8.5$. This could get a bit tedious, but it'll hardly take "all year", at least unless you're both really slow and really unlucky with the draw.

Ps. I went and calculated the odds for other numbers of couples too:

• $2$ couples: $\frac{4}{24} = \frac{1}{6} \approx 16.7\%$ chance of nobody getting their own or their partner's name
• $3$ couples: $\frac{80}{720} = \frac{1}{9} \approx 11.1\%$
• $4$ couples: $\frac{4752}{40320} = \frac{33}{280} \approx 11.8\%$
• $5$ couples: $\frac{440192}{3628800} = \frac{3439}{28350} \approx 12.1\%$
• $6$ couples: $\frac{59245120}{479001600} = \frac{16831}{136080} \approx 12.4\%$

If I'm not mistaken, as the number of couples involved tends to infinity, the probability of nobody getting their or their partner's name should tend towards the limit $e^{-2} \approx 13.5\%$, and thus the expected number of retries needed should tend towards $e^2 \approx 7.4$.

-
The general result and a derivation of the limit $\mathrm e^{-2}$ are here. –  joriki Dec 12 '11 at 10:41
It would be nice to know where you are getting these numbers from.. –  BlueRaja - Danny Pflughoeft Oct 28 '13 at 23:15
@BlueRaja: The denominator in each unreduced fraction is the total number of permutations of $n$ elements, the numerator is the number of permutations that satisfy the specified constraint. It's been a while, but I think I may have just counted them by checking each one by brute force. Joriki's answer includes a nicer formula, though. –  Ilmari Karonen Oct 28 '13 at 23:58
Ps. The heuristic argument for the $e^{-2}$ limit comes from the fact that, for large sets, a random permutation looks "locally" the same as a random function over that set. Since, in either case, the probability that a given person doesn't receive their own or their partner's name is $(n-2)/n=1-2/n$, the probability of nobody getting their own or their partner's name should be about $(1-2/n)^n=\exp(n\log(1-2/n))\approx\exp(n(-2/n))=\exp(-2)$. –  Ilmari Karonen Oct 29 '13 at 0:13

You take your own name out and your partners name out of the hat. You then draw a card which you keep. Hand the hat to your partner. They then get to draw a card, that they keep. You can now put your card and your partners card back in the hat. Hand the hat to someone else. Rinse and repteat.

-
I can see what you're thinking.. But surely the Last two sets of people know who's buying there present. –  Paul Hutchinson Nov 25 '11 at 9:51
As has been rightly pointed out, last person would then know, oh well, didn't think long enough on that one! –  Daniel Nov 25 '11 at 9:53
What happens when it arrives at the last group, though? When seven of the eight people have picked, it would be fairly obvious who is left as they would put the card in that the eighth person would draw. Or if someone's card was already drawn, what would they do? Your method requires that they search for their card, but let's say that the third person cannot find his card. Everyone then knows that either the first or the second person has his/her card. –  Warren L. Nov 25 '11 at 9:54