Claim: If David Copperfield distributes $n\ge3$ cards with numbers $1,2,\ldots,n$ over the three top hats, then only the following two types of distributions make the trick work:
- Put $1,2,3$ into different hats; put every $k\ge4$ into the same hat as its residue modulo $3$.
- Put $1$ into the first hat; put $2,\ldots,n-1$ into the second hat; put $n$ into the third hat.
Hence the answer to the puzzle is that there are exactly twelve ways to put the $52$ cards into the top hats so that the trick always works.
Proof of the claim
The proof is by induction on $n\ge3$.
The case $n=3$ is trivial, as every hat must receive at least one card (note that in this case the two distribution types coincide).
In the inductive step to $n+1$, we distinguish several cases.
(1). Assume that $n+1$ is alone in its hat and $1$ is alone in its hat.
Then we have the second distribution. Done.
(2). Assume that $n+1$ is alone in its hat, and $1$ is not alone in its hat.
Take the highest card $x$ in the hat containing $1$, and take the highest card $y$ in the third hat that neither contains $1$ nor $n+1$. Note that $2\le x$ and that $2\le y\le n$, and that $\max\{x,y\}=n$. Then the sum $S=x+y$ satisfies $n+2\le S\le (n-1)+n=2n-1$.
- The guy from the audience might pick $x$ and $y$ with sum $S$.
- On the other hand, the guy from the audience might pick card $n+1$ (which is sitting alone) together with the card $z=S-(n+1)$ from one of the other two hats. These two cards are coming from different hats, but yield the same sum $S$. Hence Copperfield's trick will fail in this case. Contradiction.
(3). Finally assume that $n+1$ is not alone in its hat. Then we may remove card $n+1$ from its hat, and get a smaller working situation for the trick with only $n$ cards. In this case, the inductive assumption exactly describes the possible distributions for cards $1,\ldots,n$.
(3a). If the cards $1,\ldots,n$ are distributed modulo $3$, then $n-2$, $n-1$, $n$ are in three different hats. Since $(n-2)+(n+1)=(n-1)+(n)$, we conclude that card $n+1$ must be in the same hat as card $n-2$; otherwise Copperfield would not know how to react when he hears the sum $2n-1$. Done.
(3b). If the cards $1,\ldots,n$ are not distributed modulo $3$, the inductive assumption yields that $1$ is on its own, that $n$ on its own, and that $2,\ldots,n-1$ are together. We may also assume that $n\ge4$ (as for $n=3$ we have the modulo $3$ distribution, which was discussed above).
In this case we are in trouble.
- First, if $1$ and $n+1$ are in different hats, then $(1)+(n+1)=(2)+(n)$
make the trick fail if Copperfield hears the sum $n+2$.
- Secondly, if $1$ and $n+1$ are in the same hat, then $(2)+(n+1)=(3)+(n)$
make the trick fail if Copperfield hears the sum $n+3$.
Hence both subcases lead to a contradiction.
This completes the proof.