HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Problems
  2. /Six friends each bring a wrapped gift with their name on it…
HardMathematicsHigh School (11–12)Pigeonhole Principle, Recursion and Graph TheoryNumericalOlympiad

Six friends each bring a wrapped gift with their name on it…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

Six friends each bring a wrapped gift with their name on it. The gifts are mixed up and handed out at random, one to each friend. The game works only if nobody gets their own gift.

Find the number of ways to hand out the gifts so that nobody gets their own. Use the recurrence for derangements, and check with inclusion and exclusion. Then find the probability that a random handing out works, to three decimal places, and compare it with 1e\dfrac{1}{e}e1​.

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

Dn=(n−1)(Dn−1+Dn−2)D_n = (n - 1)(D_{n-1} + D_{n-2})Dn​=(n−1)(Dn−1​+Dn−2​) with D1=0D_1 = 0D1​=0 and D2=1D_2 = 1D2​=1, and DnD_nDn​ is the whole number nearest to n!e\dfrac{n!}{e}en!​. The Catalan numbers are Cn=1n+1(2nn)C_n = \dfrac{1}{n + 1}\dbinom{2n}{n}Cn​=n+11​(n2n​).

The worked solution

Check an answer or open a hint to unlock the worked solution.

Have you tried it?

Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.

Step 1. The recurrence. D3=2(1+0)=2D_3 = 2(1 + 0) = 2D3​=2(1+0)=2, D4=3(2+1)=9D_4 = 3(2 + 1) = 9D4​=3(2+1)=9, D5=4(9+2)=44D_5 = 4(9 + 2) = 44D5​=4(9+2)=44, D6=5(44+9)=265D_6 = 5(44 + 9) = 265D6​=5(44+9)=265.

Step 2. Inclusion and exclusion. 720−720+360−120+30−6+1=265720 - 720 + 360 - 120 + 30 - 6 + 1 = 265720−720+360−120+30−6+1=265. The terms are (6k)(6−k)!\dbinom{6}{k}(6 - k)!(k6​)(6−k)! with alternating signs.

Step 3. The probability. 265720≈0.368\dfrac{265}{720} \approx 0.368720265​≈0.368.

Check. 1e≈0.368\dfrac{1}{e} \approx 0.368e1​≈0.368 as well. Already for 666 people the share is within 0.00020.00020.0002 of 1e\dfrac{1}{e}e1​.

Answer: 265265265 ways, and the probability is about 0.3680.3680.368.

Log in to save this for later
← All Problems
← The golden ratio is φ = (1 + √5)/2, and its partner is ψ = (1 - √5)/2…A convex polygon with 9 sides is to be cut into triangles by drawing diagonals that do not cross… →
More onPigeonhole Principle, Recursion and Graph Theory

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Derangements and Catalan numbersRecurrences and Counting by Recursion

More on this topic

  1. The 15 edges of K₆ are coloured red or blue…Advanced
  2. Three houses each need a path to each of three wells, nine paths in all, drawn on flat ground…Advanced
  3. A connected planar graph with 10 vertices is drawn without crossings, and every face of the…Hard
  4. The complete bipartite graph K_(m,n) joins each of m left vertices to each of n right vertices…
Advanced
  • A river town has five land areas, A, B, C, D and E, joined by ten bridges…Hard
  • All problems on this topic →