Secret Santa

Six people are playing Secret Santa for Christmas. They will each give one gift to someone, and each receive one gift from someone. They are not allowed to receive their own gift. How many different ways are there to exchange gifts?


The answer is 265.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

16 solutions

Linh Le
May 20, 2014

Let us denote the 6 people as A , B , C , D , E , F A, B, C, D, E, F . The total number of ways of giving gifts (including receiving one's own gift) is 6 ! = 720 6! = 720 .

We need to calculate the number of ways where A does not receive his own gift and so on for B to F. To make it easier, we will calculate the number of ways where at least one person receives his own gift and subtract this value from 720.

When we fix k points out of n (that is, n people receive their own gifts), the number of ways is ( n k ) ( n k ) ! {n \choose k}(n - k)! (because we need to choose k points to fix and arrange the remaining n - k points).

Using the principle of inclusion and exclusion, the total number of ways that satisfy the question is:

No. of ways = total permutations - permutations fixing 1 point + permutation fixing 2 points - ... + permutations fixing 6 points = 6 ! ( 6 1 ) 5 ! + ( 6 2 ) 4 ! . . . + ( 6 6 ) 1 ! = 6 ! k = 0 6 ( 1 ) k k ! = 265 = 6! - {6 \choose 1}5! + {6 \choose 2}4! - ... + {6 \choose 6}1! = 6!\displaystyle \sum_{k=0}^6 \frac {(-1)^k}{k!} = 265

Note: this kind of arrangement is called "derangement". The number of derangements for n objects is n ! k = 0 n ( 1 ) k k ! n!\displaystyle \sum_{k=0}^n \frac {(-1)^k}{k!} .

The purpose of the solution is to demonstrate the formula, not simply quote the result. Solutions which merely stated the formula for derangements were marked as incomplete.

There are several ways to approach this problem

  1. The Principle of Inclusion and Exclusion gives us a closed form solution that is easily calculated.

  2. Setting up a recursion, which involves calculating all smaller values.

  3. Understanding all the cases, which is extremely tedious (and not recommended).

Note that ! n !n is known as "subfactorial n", and not "factorial n".

Calvin Lin Staff - 7 years ago
Nathan Azaria
May 20, 2014

Let's just say the number of different ways to do this with n n persons is f ( n ) f(n) . It's obvious that f ( 1 ) = 0 f(1) = 0 and f ( 2 ) = 1 f(2) = 1 .

Consider the case with n n persons, with n 2 n\geq2 Let's just say the first person got a gift from person x x . There are two cases:

A. x x got his gift from the first person. In this case, we just need to arrange the other n 2 n-2 persons. Therefore, the number of ways is f ( n 2 ) f(n-2) .

B. x x got his gift from a person other than the first person. In this case, we can simplify the problem by thinking that x x 's gift is the first person's gift. (We can do this, since it would be the same problem anyway, x x can't get the first person's gift). So, there are f ( n 1 ) f(n-1) ways to do this.

Because there is n 1 n-1 ways to choose x x , f ( x ) = ( n 1 ) ( f ( n 1 ) + f ( n 2 ) ) f(x)=(n-1)(f(n-1)+f(n-2)) . From this, we can calculate f ( 3 ) = 2 f(3) = 2 , f ( 4 ) = 9 f(4)=9 , f ( 5 ) = 44 f(5)=44 , and finally f ( 6 ) = 265 f(6)=265 .

Can you caplain point B? I'm not clear with it.

Aditya Kumar - 5 years, 1 month ago
Jau Tung Chan
May 20, 2014

It is clear from the problem statement that the gifts must be passed in loops formed by 2 or more people, i.e. each person passes his gift to the next person in a cyclic fashion along this loop . We consider the cases of possible loops formed, which can be easily deduced:
(1) 1 loop of 6
(2) 1 loop of 4, 1 loop of 2
(3) 2 loops of 3
(4) 3 loops of 2



Case (1): -
Number of ways to choose loop of 6: 1.
Number of ways to choose order of cycle of loop of 6: 5!

Case (2): -
Number of ways to choose loop of 4: 6 C 4 ^6 C _4 (Note that loop of 2 will be fixed from this already)
Number of ways to choose order of cycle of loop of 4: 3!
Number of ways to choose order of cycle of loop of 2: 1!

Case (3): - Number of ways to choose 2 loops of 3: 6 C 3 2 ! \frac{^6 C _3}{2!}
Number of ways to choose order of cycle of loop of 3: 2!
Number of ways to choose order of cycle of loop of 3: 2!

Case (4): -
Number of ways to choose 3 loops of 3: ( 6 C 2 ) ( 4 C 2 ) 3 ! \frac{(^6 C _2)(^4 C _2)}{3!}
Number of ways to choose order of cycle of loop of 2: 1!
Number of ways to choose order of cycle of loop of 2: 1!
Number of ways to choose order of cycle of loop of 2: 1!

Hence, we conclude that the total number of ways = ( 1 ) ( 5 ! ) + ( 6 C 4 ) ( 3 ! ) ( 1 ! ) + ( 6 C 3 2 ! ) ( 2 ! ) ( 2 ! ) + ( ( 6 C 2 ) ( 4 C 2 ) 3 ! ) ( 1 ! ) ( 1 ! ) ( 1 ! ) = 265 (1)(5!) + (^6 C _4)(3!)(1!) + (\frac{^6 C _3}{2!})(2!)(2!) + (\frac{(^6 C _2)(^4 C _2)}{3!})(1!)(1!)(1!) = 265 .

Lawrence Sun
May 20, 2014

The problem is just asking for the number of derangements on 6 elements, i.e. a permutation which has no fixed points. Denote ! n !n the number of derangements on n n elements. To calculate this is clear:

Say the first element gets mapped to element i i . Now look at element i i . There are n 1 n-1 elements it can go to. If it maps to the first element, there are clearly ! ( n 2 ) !(n-2) ways to choose the rest of the mappings. If person i i does not map to the first element, remark the number of ways to determine the rest of the mappings is just ! ( n 1 ) !(n-1) then because it is as if the first element did not exist and mapping an element onto element 1 1 is mapping an element onto element i i . Thus we get the recursion ! n = ( n 1 ) ( ! ( n 1 ) + ! ( n 2 ) ) !n = (n-1)(!(n-1) + !(n-2)) .

Using this we can arrive at: ! 1 = 0 !1 = 0 obviously, ! 2 = 1 !2 = 1 . Then ! 3 = 2 !3 = 2 , ! 4 = 9 !4 = 9 , ! 5 = 44 !5 = 44 , ! 6 = 265 !6 = 265 as desired.

Aldrian Obaja
May 20, 2014

We solve the general problem for n n persons. Suppose the number of ways is D ( n ) D(n) . Suppose first person receives gift from person i i , there are n 1 n-1 ways to do that. Then we have two possibilities:

  1. Person i i receives gift from first person. In this case the problem reduces to n 2 n-2 persons, so number of ways is D ( n 2 ) D(n-2)

  2. Person i i does not receive gift from first person. In this case the problem reduces to n 1 n-1 persons, since each person has exactly one gift which he cannot receive (person i i cannot receive gift from first person, the rest cannot receive gift from themselves). So number of ways is D ( n 1 ) D(n-1) .

Therefore we have this recurrence relation D ( n ) = ( n 1 ) ( D ( n 1 ) + D ( n 2 ) ) D(n) = (n-1)(D(n-1)+D(n-2)) . Since D ( 1 ) = 0 D(1) = 0 and D ( 2 ) = 1 D(2) = 1 , we have D ( 3 ) = 2 , D ( 4 ) = 9 , D ( 5 ) = 44 , D ( 6 ) = 265 D(3) = 2, D(4) = 9, D(5) = 44, D(6) = 265 . So the answer for this problem is 265 265 .

Silvio Sergio
May 20, 2014

Let P : A n A n P: A^n \to A^n the function that maps who gives with who receives. P P is an injection (they each give one gift) and a surjection (they each receive one gift), therefore P P is a permutation. They are not allowed to give their gift to themselves, so we must consoder only permutations in which none of the elements is mapped to itself (derangements). There are different ways to count derangements, for this small case it's very easy to build D ( 6 ) \mathcal{D}(6) from smaller values:
D ( 1 ) = 0 \mathcal{D}(1)=0 , D ( 2 ) = 1 \mathcal{D}(2)=1 are trivial cases.
D ( 3 ) = 2 \mathcal{D}(3)=2 , becouse for the first gift there are two possible choices, for next items the choice is forced.
D ( 5 ) = 9 \mathcal{D}(5)=9 , becouse from the 4 ! 4! possible permutations, we have to discard:
( 4 1 ) D ( 3 ) = 4 2 \binom{4}{1}\mathcal{D}(3)=4\cdot2 permutations with a single match and a derangement of the remaining three elements,
( 4 2 ) D ( 2 ) = 6 1 \binom{4}{2}\mathcal{D}(2)=6\cdot1 permutations with 2 matches and 2 derangements, no permutations with exactly 3 matches and finally a permutation with 4 matches (identity).


similarly,
D ( 5 ) = 5 ! k = 1 5 ( 5 k ) D ( 5 k ) = 44 \mathcal{D}(5)=5!-\sum_{k=1}^5\binom{5}{k}\mathcal{D}(5-k)=44 D ( 6 ) = 6 ! k = 1 6 ( 6 k ) D ( 6 k ) = 265 \mathcal{D}(6)=6!-\sum_{k=1}^6\binom{6}{k}\mathcal{D}(6-k)=265

Javier Gutierrez
May 20, 2014

We divide in cases:

(Note: (a, b, c) means that is divided into 3 groups of a, b and c persons respectively)

  • Case 1: They give one gift by pairwise. (2, 2, 2)

We can choose the first pair of ( 6 4 ) = 15 {6 \choose 4} = 15 ways, the second pair of ( 4 2 ) = 6 {4 \choose 2} = 6 ways and the third is determined.

Therefore, we obtain 15 × 6 × 1 = 90 15 \times 6 \times 1 = 90 but is the same case if the pairs are (AB, CD, EF) and (AB, EF, CD), then we divide by 6. Then we obtain 15 ways.

  • Case 2: (3, 3)

We can choose the first group of ( 6 3 ) = 20 {6 \choose 3} = 20 ways and the second is determined. In each group, we have 2 forms in each group for give a gift. (If the people are A,B,C the 2 forms are A \rightarrow B \rightarrow C \rightarrow A or A \rightarrow C \rightarrow B \rightarrow A).

Therefore, we obtain 20 × 4 = 80 20 \times 4 = 80 but is the same case if the groups are (ABC, DEF) and (DEF, ABC), then we divide by 2. Then, we obtain 40 ways.

*Case 3: (4, 2)

We can choose the pair of ( 6 2 ) = 15 {6 \choose 2} = 15 ways and the other group is determined. In the 4-group, we have 6 distribution forms: A \rightarrow B \rightarrow C \rightarrow D \rightarrow A, A \rightarrow B \rightarrow D \rightarrow C \rightarrow A, A \rightarrow C \rightarrow B \rightarrow D \rightarrow A, A \rightarrow C \rightarrow D \rightarrow B \rightarrow A, A \rightarrow D \rightarrow B \rightarrow C \rightarrow A and A \rightarrow D \rightarrow C \rightarrow B \rightarrow A.

Therefore, we obtain 15 × 6 × 1 = 90 15 \times 6 \times 1 = 90 ways.

  • Case 4: (6) in a circle

We obtain 5! = 120 ways, because if A is fixed, the other guys can permute of 5!.

(The cases with one-person-groups is not possible because this person don't give a gift with herself)

Finally, we obtain 15 + 40 + 90 + 120 = 265 ways.

Hugo Terceiro
May 20, 2014

Consider a set J = { 1 , 2 , 3 , . . . , n } J=\{1, 2, 3, . . ., n\} . We say that a permutation σ \sigma of J J is chaotic when the i t h i^{th} element on the identity permutation is not the i t h i^{th} element on σ \sigma .

That said, we have that the number D n D_n of chaotic permutations of a set with n n elements is:

D n = n ! × [ 0 i = n ( 1 ) i i ! ] D_n = n! \times \left[{\displaystyle \sum_0^{i=n}} \dfrac{(-1)^i}{i!}\right]

so, knowing that the none of the 6 people can end with their own present, we have a chaotic permutation on a set with 6 elements, D 6 D_6 , if you may.

Then we have:

D 6 = 6 ! × [ 0 i = 6 ( 1 ) i i ! ] D_6 = 6! \times \left[{\displaystyle \sum_0^{i=6}} \dfrac{(-1)^i}{i!}\right]

= 6 ! [ 1 0 ! 1 1 ! + 1 2 ! 1 3 ! + 1 4 ! 1 5 ! + 1 6 ! ] = 6! \left[\dfrac{1}{0!} - \dfrac{1}{1!} + \dfrac{1}{2!} - \dfrac{1}{3!} + \dfrac{1}{4!} - \dfrac{1}{5!} + \dfrac{1}{6!}\right]

= 265 = 265

There are 265 265 different ways to distribute the presents.

Ramesh Babu
May 20, 2014

if n things are arranged in a row then number of ways in which they can be arranged so that none of them occupy original place is

n!(1-(1/(1!))+(1/(2!))-..+(-1)^n(1/(n!)))

hence weget for n=6 265

Daniel Viana
May 20, 2014

The problem ask how many differents ways can we make a chaotic permuation of 6 elements.We have just to aplly the formula(Dn) N=6!(1/0!-1/1!+1/2!-1/3!+1/4!-1/5!+1/6!) N=265

Apurv Goel
May 20, 2014

Using derangement theorem

total ways = n!{ 1 2 ! \frac {1}{2!} + 1 3 ! \frac {1}{3!} + 1 4 ! \frac {1}{4!} + ................+ 1 n ! \frac {1}{n!} }

where n! = n factorial

putting n = 6 we get total ways = 265

Christopher Boo
Mar 25, 2014

Technique: Derangement

The number of giving gift to someone, and since they are not allowed to receive their own gift, the number of ways to exchange is

! 6 !6

= 6 ! ( 1 1 1 ! + 1 2 ! 1 3 ! + . . . + 1 6 ! ) =6!(1-\frac{1}{1!}+\frac{1}{2!}-\frac{1}{3!}+...+\frac{1}{6!})

= 256 =256

This problem called Dearrangement problem we can solve this problem with recursive , that is : Dn = (n-1)*(Dn-1+Dn-2) with base case : D1 = 0 and D2 = 1 so we cand find that D6 is 265

Aayush Sureka
May 20, 2014

Ok, I knew the formula for this but for getting it, we need to do it by Induction I guess. Suppose we do it for 2 people. The answer is obvious, its 1 way. We can also write 2 ways as 2 ! [ ( 2 1 ) × ( 2 1 ) ! ] + [ ( 2 2 ) × ( 2 2 ) ! ] 2! - [{2 \choose 1}\times (2-1)!] + [{2 \choose 2}\times (2-2)!] 2 ! 2 ! 1 ! + 2 ! 2 ! \Rightarrow 2! - \frac {2!}{1!} + \frac {2!}{2!}

Now, going on with 3 people, its 2 ways. We can also write 2 ways as 3 ! [ ( 3 1 ) × ( 3 1 ) ! ] + [ ( 3 2 ) × ( 3 2 ) ! ] [ ( 3 3 ) × ( 3 3 ) ! ] 3! - [{3 \choose 1}\times (3-1)!] + [{3 \choose 2}\times (3-2)!] - [{3 \choose 3}\times (3-3)!] 3 ! 3 ! 1 ! + 3 ! 2 ! 3 ! 3 ! \Rightarrow 3! - \frac {3!}{1!} + \frac {3!}{2!} - \frac {3!}{3!}

Therefore, If we generalize for N people we get, N ! N ! 1 ! + N ! 2 ! N ! 3 ! . . . ± N ! N ! N! - \frac {N!}{1!} + \frac {N!}{2!} - \frac {N!}{3!}... \pm \frac {N!}{N!} where N ! R ! \frac {N!}{R!} is no. of ways to distribute the gifts to each other such that atleast R out of N people gift themselves.

Huang Sang
May 20, 2014

It is the factorial 6

Hungry Cap
Mar 22, 2014

The answer is simply the 6th subfactorial number: 265.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...