Derangement Calculator
Calculate !n (subfactorial) - the number of permutations where no element appears in its original position.
Calculate !n
!5 (Derangements)
44
5! (Permutations)
120
Probability of Derangement
36.6667%
!5 / 5! = 0.36666667
Limit as n β β
36.7879%
1/e β 0.36787944
Derangement vs Factorial
| n | !n | n! | !n/n! |
|---|---|---|---|
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 0.000000 |
| 2 | 1 | 2 | 0.500000 |
| 3 | 2 | 6 | 0.333333 |
| 4 | 9 | 24 | 0.375000 |
| 5 | 44 | 120 | 0.366667 |
| 6 | 265 | 720 | 0.368056 |
| 7 | 1854 | 5040 | 0.367857 |
| 8 | 14833 | 40320 | 0.367882 |
| 9 | 133496 | 362880 | 0.367879 |
| 10 | 1334961 | 3628800 | 0.367879 |
| 11 | 14684570 | 39916800 | 0.367879 |
Formulas
Recurrence
!n = (n-1)(!(n-1) + !(n-2))
Inclusion-Exclusion
!n = n! Γ Ξ£(-1)^k/k!
Nearest Integer
!n = round(n!/e)
Limit
lim(!n/n!) = 1/e
The Hat Check Problem
If n people check their hats and the hats are returned randomly, what is the probability that no one gets their own hat back? The answer is !n/n!, which approaches 1/e β 36.79% as n increases. Remarkably, this probability is nearly constant for n β₯ 4.