Work out subfactorial instantly with clear inputs, formula shown and shareable results.
The subfactorial !n counts derangements — permutations leaving no item in its original place. It satisfies the recurrence !n = n·!(n−1) + (−1)ⁿ, and !n / n! tends to 1/e ≈ 0.3678794.
Derangement recurrence
!n = n·!(n−1) + (−1)ⁿ, with !0 = 1
Limit
!n / n! → 1/e
265, out of 720 total permutations, a probability of about 0.368.
If n people collect hats at random, the chance nobody gets their own is !n/n!, which is essentially 1/e for any n above about 5.