Five people hand their hats to a cloakroom that returns them at random. Out of 5! = 120 possible returns, the number in which nobody receives their own hat is 44. The workbench gets there from the alternating sum 120·(1/2 − 1/6 + 1/24 − 1/120), which is 60 − 20 + 5 − 1: the inclusion–exclusion recipe, counted over pairs, triples and quadruples of people who do get their own hat back.
The probability that nobody matches is 44/120 = 0.3666…, and it converges to 1/e = 0.367879… as the number of hats grows, which is why the third link — 120 divided by the thirteen-digit e — prints 44.145532940574. That is not the answer, it is the answer's approximation: !n is the nearest integer to n!/e for every n ≥ 1, and 44 is what rounding 44.1455 gives. The same 1/e turns up in the shuffle problem fifty-two hats away, where the expected number of fixed points is 1 whatever the deck size.
Answer
44
How to read it
The inclusion–exclusion sum on the workbench. The second link is 5!, the total number of returns, and the third is 120/e, whose nearest integer is the answer.
Source
!n, the number of derangements, from the inclusion–exclusion sum n!(1/0! − 1/1! + 1/2! − … + (−1)ⁿ/n!); the matching problem is discussed by Abraham de Moivre in 1708 and by Montmort in the same years, and the limit !n/n! → 1/e is the standard result
Work it in the calculator
These links open the right calculator with this problem's numbers already typed in. The line above is what the screen should show — check it yourself.