The number of different ways in which eight persons, with eight hats,
can each take the wrong hat, is 14,833.
Here are the successive solutions for any number of persons from one to
eight:--
1 = 0
2 = 1
3 = 2
4 = 9
5 = 44
6 = 265
7 = 1,854
8 = 14,833
To get these numbers, multiply successively by 2, 3, 4, 5, etc. When the
multiplier is even, add 1; when odd, deduct 1. Thus, 3 × 1 - 1 = 2; 4 ×
2 + 1 = 9; 5 × 9 - 1 = 44; and so on. Or you can multiply the sum of the
number of ways for n - 1 and n - 2 persons by n - 1, and so get the
solution for n persons. Thus, 4(2 + 9) = 44; 5(9 + 44) = 265; and so on.