Before any algebra, let me say what the experiment is. Handing n labeled hats back at random, one to each student, is exactly drawing a permutation of n objects uniformly from all n factorial of them.
A student who gets their own hat is what the textbooks call a fixed point of that permutation, so the number of happy students is the number of fixed points. I will call it X.
So the question is not really a story about hats; it asks for one specific column of the distribution of X, the column n minus one. Once I see that, I know I am allowed to attack it by structure or by counting, and I should try structure first.
Here is the structural argument. Give n minus one students their own hats. That uses up n minus one specific hats, so precisely one hat remains, and the only hat left is the last student's own hat.
He has no choice in the matter: whatever he does, he is correct. So the configuration 'exactly n minus one correct' cannot be completed; it always collapses into 'all n correct'.
I want to commit to this before I compute anything: the count in the column n minus one must be zero for every n, starting at n equals one, where the question asks for zero correct and the single student is trapped into being correct. If my enumeration later shows even one arrangement in that column, my argument is wrong and I will say so.
Let me draw the smallest case where I can see the mechanism, n equals four with three students already holding their own hats.
Three own hats are consumed, one hat remains, one student remains, and the remaining hat is his. The dashed arrow is not a choice; it is a forced move.
Notice what the picture proves: it is not that three-correct is rare. It never happens at all. The count of happy students can jump from two to four, but it cannot stop at three.
Now the counting route, which is the route the question tempts you into. If I prescribe which k students are correct, the remaining n minus k students must all be wrong among the remaining n minus k hats: a derangement. So the count is n choose k times D of n minus k.
Feed in k equals n minus one: n ways to choose the winners, and then the one leftover student must miss his own hat, derangements of one object, which is zero. One object, one hat, no derangement exists.
So the formula agrees with the structural argument, and it agrees for the same reason: D of one equals zero is exactly the forcing step written in the language of derangements.
I will not trust my own argument until a computer has counted. For every n from one to eight I enumerated all n factorial permutations and tallied each fixed-point count.
The column n minus one is zero at every single n; that is eight zeros, exactly as predicted. The neighboring column n minus two is alive: three, six, ten, fifteen, twenty-one, twenty-eight from n equals three up to eight. So the zeros are not a bug in my code that counts everything as zero.
Look at the n equals six row: two sixty-five, two sixty-four, one thirty-five, forty, fifteen, zero, one. The bars fall smoothly and then the second-to-last one is simply missing, and the row still sums to seven hundred and twenty, so nothing leaked.
The derangement numbers deserve two independent computations before I lean on them. Route one is inclusion-exclusion: m factorial times the alternating sum of one over j factorial. Route two is the classic recurrence, D of m equals m minus one times D of m minus one plus D of m minus two, with the two initial values computed on the spot rather than quoted.
Both routes produced identical values up to m equals eight, and both match the zero-fixed-points column of my brute-force table; for instance, the two hundred and sixty-five derangements of six objects appear in all three places.
Then I ran the general formula against every cell of the enumeration, all forty-four pairs with n at most eight: the maximum deviation is exactly zero. The formula is not just fitting the answer for this question; it is right everywhere nearby.
A simulation as a third opinion, with one trap of its own. I fixed the seed, and my ten thousand trial block is literally the first ten thousand draws of the hundred thousand trial block, so those two rows are nested samples, not independent confirmations, and I will not present them as two votes.
Every standard error comes with its z. Most cells sit inside one or two standard errors, but the honest report is this: the worst cell, found by taking the maximum absolute z over the table, is n equals eight, exactly one fixed point, at ten thousand draws; z equals plus two point three one, beyond two. That is roughly the rate you would expect when you look at many cells, and the same cell at the larger nested sample gives z equals plus zero point one zero, so nothing is broken; but I am not going to claim everything sat inside one standard error, because it did not.
Two housekeeping points. In one named cell, n equals six, nobody correct, going from ten thousand to a hundred thousand trials divided the standard error by three point one six two two eight, which is root ten, not by two; and that division compares zero point zero zero four eight two two seven seven with zero point zero zero one five two five zero nine, both from that same cell, not from the similar-looking four point eight two two in the row where n equals eight and the fixed points equal one. And my error bars use the theory p, not the observed frequency: for the n equals six, X equals zero cell the two conventions give zero point zero zero one five two five one versus zero point zero zero one five two seven three, already different in the fourth significant digit.
And the cell this question is actually about: zero hits in a hundred thousand draws at n equals six, and zero in another hundred thousand at n equals eight, so two hundred thousand draws in all. For that cell the theoretical p is zero, so the standard error is zero and z is undefined: the simulation cannot test a zero-probability event, it can only agree with it. The real evidence there is the forcing argument and the exhaustive count, and I would say that out loud rather than write 'perfect match'.
So the answer is zero, for every n at least one; not approximately zero, structurally zero.
The generalisation is where the insight lives. The forcing argument singles out exactly one column of the distribution. Every neighbor is fine: n minus two correct happens with probability one over twice n minus two factorial: the two leftover students just swap hats. And at least n minus one is just all n, one over n factorial.
The moments make the oddity precise. The expected number of correct hats is one for every n, no matter how large, and the variance is one from n equals two on. A distribution sitting on essentially every value from zero to n, with mean one, but with a single forbidden gap exactly one below the top.
Where does the mechanism stop? Nowhere inside this model. But it is model-specific: if hats could be shared or some student could pass, the counting stops being permutations and the forcing argument loses its grip.
For the moments, the brute-force tally and the indicator calculation give exactly the same values.
If you want one more layer: for fixed k and growing n, the k-th column converges to e to the minus one over k factorial: the fixed points of a random permutation are asymptotically Poisson with mean one. My table shows it: the zero-fixed-points probability is already point three six seven eight eight two at n equals eight against one over e of point three six seven eight seven nine.
The mean-one fact and the Poisson limit are the same story: almost all the mass sits in the first few columns, which is why the forbidden column at the very top costs nothing in probability; it was empty anyway.
I would offer this as the epilogue: the trap question is really a window into the whole fixed-point distribution.
Then the answer changes completely, and this is the boundary the question is testing. At least n minus one splits into exactly n minus one, which is empty, plus all n, which is the identity permutation alone.
So the probability is one over n factorial: at n equals six, one over seven hundred twenty, point zero zero one three eight nine. The enumeration gives the same: my n equals six row has a single permutation at k equals six and none at k equals five.
Nonzero, and I can name the mechanism: choose the two students who miss, then they must swap hats; that is one derangement of two objects. So the count is n choose two times D of two, and D of two is one.
The probability is one over two times n minus two factorial: at n equals four that's six over twenty-four, a quarter; at n equals six, fifteen over seven hundred twenty, point zero two zero eight three. Both match my enumeration column by column.
Indicator variables. For each student, the chance their own hat comes back to them is one in n by symmetry, so the expectation of the total is n times one over n, which is one; no independence needed, and that matters because these indicators are badly dependent.
The second moment takes one more step: the chance two named students are both correct is one over n times n minus one, so the expected number of ordered correct pairs is n times n minus one times that, which is one. Then the variance is one plus one minus one squared, which is one, for n at least two.
I checked both against the enumeration for n up to eight: mean exactly one everywhere, variance exactly one from n equals two on, and zero at n equals one, where the single student is always correct.
That is the genuine derangement question, D of n over n factorial, and it is the only column where the full formula earns its keep. Inclusion-exclusion gives one minus one plus one over two minus one over six and so on, which converges to one over e, about point three six seven eight seven nine.
My numbers: n equals four gives nine over twenty-four, three eighths, not a quarter; n equals six, two hundred sixty-five over seven hundred twenty; n equals eight, fourteen thousand eight hundred thirty-three over forty thousand three hundred twenty, point three six seven eight eight two. Already within three millionths of one over e at n equals eight.
Note the contrast with today's question: here the formula does real work; there it collapses to zero through D of one. Knowing which situation you are in is the whole point of the trap.