The trick
A spectator draws $k$ cards from a deck of $n$ and hands them to the magician's assistant. The assistant shows $k-1$ of them to the magician in a chosen order. The magician names the card that was not shown. This can be done exactly when $n \le k!+k-1$, which is Kleber's theorem, and those values are A030495. For $k = 5$ the largest deck has $124$ cards, against the $52$ of a standard deck.
Kagey asks what happens when the assistant is allowed to hide more than one card.
The assistant may show any number of cards less than $k$, in order, and the magician must name all of the remaining cards. How large a deck can be handled?
Four related questions come with it. How many encodings are there up to relabeling (R1). What happens if the magician need only name one of the hidden cards (R2). What happens with $\ell$ identical copies of the deck (R3). What is the largest deck when the assistant shows exactly $k-2$ cards, or more generally $k-j$ (R4). We answer the main question and R4 completely and R2 in part. We do not touch R1 or R3.
The counting criterion
Everything on this page comes from one statement. Fix nonnegative integers $c_0, \dots, c_{k-1}$. A message is a sequence of $l \le k-1$ distinct cards together with one of $c_l$ extra signals, and it is available to a hand when all of its cards lie in that hand. A strategy sends every hand to an available message in such a way that the magician can recover the hand. The magician already sees the shown cards, so recovering the hand is the same as naming the hidden ones. A strategy is therefore exactly an injective choice of an available message for each hand.
The vector $c$ carries every rule in the problem. The original trick is $c_{k-1} = 1$ and the rest zero. Showing exactly $k-j$ cards is $c_{k-j} = 1$. The relaxed rule of the question is $c_0 = \dots = c_{k-1} = 1$. If each shown card may also be turned in one of $R$ ways, then $c_l = R^l$.
A strategy exists if and only if $$\binom{n}{k} \;\le\; \sum_{l=0}^{k-1} c_l \,(n)_l, \qquad (n)_l = n(n-1)\cdots(n-l+1).$$
The right side counts the messages, so one direction is the pigeonhole principle. The other is a fractional matching.
Write $B = \binom nk$ and $M_l = c_l (n)_l$. Since $\sum_l M_l \ge B$ we may pick reals $x_l$ with $0 \le x_l \le M_l/B$ and $\sum_l x_l = 1$. Put weight $x_l (k-l)!/(c_l\,k!)$ on every edge between a hand and an available message of length $l$. A hand has $c_l\,k!/(k-l)!$ available messages of length $l$, so the weights at a hand sum to $\sum_l x_l = 1$. A message of length $l$ is available to $\binom{n-l}{k-l}$ hands, so the weights there sum to $x_l B / M_l \le 1$. For any set $S$ of hands the weight leaving $S$ is $|S|$ and it all lands in the neighbourhood of $S$, so $|S| \le |N(S)|$. Hall's theorem gives the matching.
The bipartite graph is not regular in general, and the argument does not need it to be. That is what makes the criterion cover mixed rules. The argument produces no usable strategy. For the original trick Kleber's article has an explicit one, and we checked it at $n = 3$, $8$ and $27$.
Exactly $k-j$ cards shown
Write $N_j(k)$ for the largest deck when the assistant shows exactly $k-j$ cards and the magician names the $j$ hidden ones.
A strategy exists if and only if $(n-k+1)(n-k+2)\cdots(n-k+j) \le k!$. Hence $N_j(k) = k+m$, where $m$ is the largest integer with $(m+1)(m+2)\cdots(m+j) \le k!$.
In particular $N_1(k) = k!+k-1$, $N_k(k) = k$, and
$$N_2(k) = \left\lfloor \frac{2k-3+\sqrt{1+4\,k!}}{2} \right\rfloor .$$For every $1 \le j \le k$ the value sits in a narrow window,
$$(k!)^{1/j} + k - \frac{j+3}{2} \;<\; N_j(k) \;\le\; (k!)^{1/j} + k - 1 ,$$which we checked for $k \le 11$.
| $N_j(k)$ | $j=1$ | $2$ | $3$ | $4$ | $5$ | $6$ |
|---|---|---|---|---|---|---|
| $k=2$ | 3 | 2 | ||||
| $3$ | 8 | 4 | 3 | |||
| $4$ | 27 | 7 | 5 | 4 | ||
| $5$ | 124 | 14 | 8 | 6 | 5 | |
| $6$ | 725 | 31 | 13 | 8 | 7 | 6 |
| $7$ | 5046 | 76 | 22 | 13 | 9 | 8 |
| $8$ | 40327 | 207 | 40 | 19 | 13 | 10 |
| $9$ | 362888 | 609 | 78 | 31 | 19 | 14 |
The first column is A030495 shifted by one and the second is A372265. The criterion itself is not new. It was stated and proved in a 2011 blog post, by way of the Kőnig–Egerváry theorem. Chen and coauthors give the same inequality only as an upper bound, and record the case $j = 2$ in A372265 as an information-theoretic bound. What the corollary adds is that the bound is attained for every $k$, so A372265 is the true maximum rather than a ceiling. For $k = 6$ with two cards hidden the largest deck is $31$, while the strategy of Chen and coauthors handles $29$.
Some decks fit exactly. The largest deck at $j = 1$ always does, because $\binom nk$ divided by $(n)_{k-1}$ is $(n-k+1)/k!$, which is $1$ at $n = k!+k-1$. At that deck there is no slack at all: the hands and the messages are equinumerous, and every ordered $(k-1)$-tuple is used once. The first figure is that fit at $k = 3$. For $k = 6$ and $j = 3$ the deck $n = 13$ gives $\binom{13}{6} = 1716 = 13 \cdot 12 \cdot 11$, the same thing with three cards hidden.
The relaxed rule
Suppose the assistant may show any number of cards from $0$ to $k-1$, in order, and the magician must name all the others. The largest deck is $k!+k-1$, the same as when exactly $k-1$ cards must be shown.
This answers Kagey's question. Always showing $k-1$ cards is allowed, so the lower bound is Kleber's. For the upper bound, put $m = n-k$ and let $T$ be the number of messages of length $k-1$. The number of messages of length $k-i$ is $T/((m+2)(m+3)\cdots(m+i))$, which is at most $T/(m+2)^{i-1}$, so all lengths together give at most $T(m+2)/(m+1)$ messages. The number of hands is $T(m+1)/k!$. For $n \ge k!+k$ we have $m+1 > k!$, and then $(m+1)/k! > (m+2)/(m+1)$. There are more hands than messages.
The margin is small. For $k = 4$ and $n = 28$ there are $20475$ hands and $20441$ messages of length at most $3$. For $k = 3$ and $n = 9$ the numbers are $84$ and $82$. Requiring the assistant to show at least one card changes nothing for $k \ge 2$, because the strategy that reaches $k!+k-1$ always shows $k-1$ of them.
Now let $R_j(k)$ be the largest deck when the assistant may show at most $k-j$ cards and the magician names all the others. Always showing exactly $k-j$ is allowed, so $R_j(k) \ge N_j(k)$, and the theorem above says $R_1(k) = N_1(k)$.
$R_j(k) \in \{N_j(k),\, N_j(k)+1\}$ for all $1 \le j \le k$. Both values occur for $j \ge 2$. Among $2 \le j \le k \le 12$ the gain of one card happens exactly at $$(k,j) = (9,2),\ (10,3),\ (11,3),\ (11,4),\ (12,2),$$ where $R_j(k)$ is $610$, $162$, $351$, $88$ and $21897$.
The bound $R_j(k) \le N_j(k)+1$ is proved, by the same geometric series with $f(m) = (m+1)\cdots(m+j)$ in place of $m+1$. The list of five pairs is computed, with exact integers and again with exact fractions after dividing the criterion through by $(n)_k$. The same computation shows that forbidding the empty message leaves $R_j(k)$ unchanged for every $1 \le j < k \le 12$.
So a deck of $610$ can be handled with nine cards drawn and two hidden, but only if the assistant sometimes shows fewer than seven cards. There are about $3.0371 \times 10^{19}$ hands, about $3.0360 \times 10^{19}$ messages of length $7$, and about $5.03 \times 10^{16}$ of length $6$. We have no explicit strategy for this deck.
Naming only one hidden card
Now the assistant shows exactly $l$ cards in order, with $1 \le l \le k-1$, and the magician names one card, which must be one of the $k-l$ hidden ones. The assistant's map need not be injective any more, so the counting criterion no longer applies. Write $G(k,l)$ for the largest deck. At $l = k-1$ this is the original trick, so $G(k,k-1) = k!+k-1$.
For $1 \le l \le k-1$, $$\left\lfloor \frac{k-1}{l} \right\rfloor \bigl((l+1)!+l\bigr) \;\le\; G(k,l) \;\le\; \frac{k!}{(k-l-1)!} + l .$$
The lower bound splits the deck into $\lfloor (k-1)/l \rfloor$ groups and runs the original trick for hands of size $l+1$ inside whichever group holds enough of the hand. The upper bound counts: a sequence with its guess serves only the hands containing those $l+1$ cards. The two agree at $l = k-1$ and are far apart otherwise. For $l = 1$ we can close the gap.
$G(k,1) = 3(k-1)$ for every $k \ge 2$. If the assistant shows one card and the magician must name one of the other $k-1$, the largest deck has $3(k-1)$ cards.
Let $\gamma$ be the magician's map, so $\gamma(a) \ne a$, and let $\Gamma$ be the graph on the deck with an edge $\{a, \gamma(a)\}$ for each card $a$. The assistant can handle a hand exactly when it contains some $a$ together with $\gamma(a)$, that is, when it is not independent in $\Gamma$. So $\Gamma$ has no independent set of size $k$. A component of $\Gamma$ on $v$ vertices has at most $v$ edges, so it is a tree or has exactly one cycle, and either way it has an independent set of at least $v/3$ vertices. Adding over components gives $n/3 \le k-1$. The lower bound is the proposition, and it is the triple construction below.
Counting alone would allow more. For $k = 3$ the counting bound of the proposition is $7$ and the truth is $6$, so for this variant the pigeonhole is not the whole story. The real question is a covering problem. The sets consisting of a shown sequence together with its guess form a family of $(l+1)$-sets meeting every $k$-set, and distinct members of the family need distinct sequences. Families with the first property are Turán systems, and their least size $T(n,k,l+1)$ is unknown in general, already for $(k, l+1) = (4,3)$.
$15 \le G(4,2) \le 18$.
The lower bound is Turán's family on $15$ points: three parts of size $5$, the triples inside a part, and the triples with two points in one part and one in the next. It has $180$ members, and a matching gives each member a distinct ordered pair of its own points. The resulting strategy was checked against the definition on all $1365$ hands. The upper bound uses $T(8,4,3) = 20$, found by exhaustive search, together with the fact that $T(n,4,3)/\binom n3$ does not decrease in $n$. Turán's family on $16$ points has $225$ members and $16 \cdot 15 = 240$ ordered pairs to spend, and it admits no such assignment. Whether some other family works at $16$, $17$ or $18$ we do not know.
What was checked
Two scripts accompany the paper. One uses the standard library only and takes about $75$ seconds. The other repeats the work by different methods that share no code, in about three minutes. Every check passes.
- The encoding on Kagey's problem page is a strategy for $k = 3$, $n = 8$: $56$ hands, $56$ distinct ordered pairs, each drawn from its hand. That is the first figure.
- The criterion was confirmed by maximum matching in more than $3000$ feasible cases with $k \le 6$, signal counts up to $3$ for $k \le 4$, and decks up to $28$ cards at $k = 4$. In $96$ of them no single length has enough messages, so the assistant has to mix lengths. The extra signals were included for that reason. With every $c_l \le 1$ the smallest mixing case we found is $k = 14$ on a deck of $33$ with at most $6$ cards shown, where $818{,}809{,}200$ hands meet $826{,}945{,}186$ messages and the longest allowed length supplies only $797{,}448{,}960$ of them. That is far past what a matching computation can reach. The equivalence was rechecked with a second matching algorithm, and on tiny decks by testing Hall's condition on every set of hands.
- The table of $N_j(k)$ was computed twice, by scanning the criterion over $n$ and from the product form, and its small entries a third time by matching deck by deck. The closed form for $j = 2$ agrees with every term published in A372265, out to $k = 30$.
- The five gains of $R_j(k)$ over $N_j(k)$ for $k \le 12$, with exact integers and separately with exact fractions.
- $G(k,1) = 3(k-1)$ for $k = 2$, $3$, $4$ by a branching search, and again by enumerating every map $\gamma$ for $k = 2$, $3$ and by an integer program for $k = 4$.
- The $15$-card strategy on all its hands, $T(7,4,3) = 12$ and $T(8,4,3) = 20$ by exhaustive search and by integer programming, and the failure of Turán's family at $16$ by two matching algorithms.
Every number on this page was recomputed independently of the paper before it was written down.
What is open
- R1, the number of encodings up to relabeling, is untouched. Kleber asks it too.
- R3, $\ell$ identical copies of the deck, is untouched. With repeated cards the hands fall into several orbits, so the criterion of section 2 does not apply as it stands. Chen and coauthors treat two copies, and reach the counting bound there for $k \le 3$.
- $G(k,l)$ for $2 \le l \le k-2$, starting with $G(4,2) \in \{15,16,17,18\}$. An integer program for $16$ with a general family did not finish in nine minutes.
- An explicit strategy for the deck of $610$. The proof of the criterion is a matching argument and hands back nothing a magician could use.
- A description of the pairs $(k,j)$ with $R_j(k) = N_j(k)+1$. The five found for $k \le 12$ have no evident pattern.