59

Let $k$ be a positive integer. A spectator is given $n=k!+k−1$ balls numbered $1,2,\dotsc,n$. Unseen by the illusionist, the spectator arranges the balls into a sequence as they see fit. The assistant studies the sequence, chooses some block of $k$ consecutive balls, and covers them under their scarf. Then the illusionist looks at the newly obscured sequence and guesses the precise order of the $k$ balls they do not see.

Devise a strategy for the illusionist and the assistant to follow so that the trick always works.

(The strategy needs to be constructed explicitly. For instance, it should be possible to implement the strategy, as described by the solver, in the form of a computer program that takes $k$ and the obscured sequence as input and then runs in time polynomial in $n$. A mere proof that an appropriate strategy exists does not qualify as a complete solution.)

Source: Komal, October 2019, problem A $760$.
Proposed by Nikolai Beluhov, Bulgaria, and Palmer Mebane, USA


I can prove that such a strategy must exist:

We have a set $A$ of all permutations (what assistant sees) and a set $B$ of all possible positions of a scarf (mark it $0$) and remaining numbers (what the illusionist sees).

We connect each $a$ in $A$ with $b$ in $B$ if a sequence $b$ without $0$ matches with some consecutive subsequence in $a$. Then each $a$ has degree $n-k+1$ and each $b$ has degree $k!$. Now take an arbitrary subset $X$ in $A$ and let $E$ be a set of all edges from $X$, and $E'$ set of all edges from $N(X)$ (the set of all neighbours of vertices in $X$). Then we have $E\subseteq E'$ and so $|E|\leq |E'|$. Now $|E|= (n-k+1)|X|$ and $|E'| = k!|N(X)|$, so we have $$ (n-k+1)|X| \leq k!|N(X)|\implies |X|\leq |N(X)|.$$ By Hall marriage theorem there exists a perfect matching between $A$ and $B$...

...but I can not find one explicitly. Any idea?


Update: 2020. 12. 20.

nonuser
  • 90,026
  • 1
    Interesting. Working out the case $k=2$, $n=3$. In this case the scarf can cover either the two leftmost balls or the two rightmost balls. If the agreement is that when the order is $123$, the scarf is on the left, it follows that with $213$ scarf must be on the right (otherwise the illusionist can't cope). Therefore with $231$ the scarf must be on the left and we can continue. The outcome for the case $k=2$ is that if the permutation is even, the scarf covers the leftmost balls, but if the permutation is odd then the scarf is on the right. – Jyrki Lahtonen Jul 24 '20 at 19:00
  • I have no idea how well this type of "forcing" works when there are more positions for the scarf. – Jyrki Lahtonen Jul 24 '20 at 19:00
  • I believe finding a strategy for $k=3$ will be easy to generalize it. – nonuser Jul 24 '20 at 19:16
  • That's probably right. We are to partition all the orderings into $k!$ piles. Unlike in the case $k=2$ I don't see why it would be necessary for all the permutations with e.g. $1,2,\ldots,k$ in the first $k$ positions (in some order) to be in distinct piles, but that may simplify finding the construction (if it works, a big if). – Jyrki Lahtonen Jul 24 '20 at 19:21
  • 2
    In the case $k=3$ there are $6$ possible positions for the scarf. Those correspond to six possible mappings $f_i, i=1,2\ldots,6$, from $S_8$ to $S_3$ (how are the 3 balls under the scarf shuffled). If the "pile" of a permutation $\sigma\in S_8$ is the product of $f_i(\sigma)$s in $S_3$, that would be a somewhat generalizable idea. But I have no idea whether it works. Just tossing an idea in the air. – Jyrki Lahtonen Jul 24 '20 at 19:27
  • I don't think it is quite that simple (doesn't match the $k=2$ construction). Still, it feels natural to use $S_k$ as the set "indexing" the positions of the scarf. – Jyrki Lahtonen Jul 24 '20 at 19:39
  • 2
    https://codegolf.stackexchange.com/questions/165390/professor-at-mit-can-read-minds https://math.stackexchange.com/questions/3324626/explanation-of-the-solution-to-fitch-cheneys-124-card-trick https://puzzling.stackexchange.com/questions/6569/a-five-card-trick-how-does-it-work – nonuser Jul 24 '20 at 20:55
  • 1
    http://www.apprendre-en-ligne.net/crypto/magie/card.pdf – nonuser Jul 24 '20 at 21:07
  • 2
    Regarding the .pdf to which you have just linked, there was a company with a booth at the last Joint Math Meetings which gave several examples using a similar scheme (e.g. they showed four cards in some order, and a "hidden" card). The goal was to figure out how to infer the value of the hidden card from the four cards shown. I got a really nice insulated water bottle for coming up with a solution (though, I must admit, a colleague provided me with a great deal of help). :) – Xander Henderson Jul 24 '20 at 21:24
  • https://www.cimat.mx/ciencia_para_jovenes/codigos/5cardTrick.htm ams.org/publicoutreach/feature-column/fcarc-mulcahy7 – nonuser Jul 25 '20 at 07:31
  • 2
    I have found an explicit solution for $k=3$, however it is not very enlightening which is why I post this as a comment and not an answer. You can view it here. The solution consists of (permutation, cloth index) pairs, with the cloth index and ball numbering both starting at $0$. This does not rule out the existence of a more structured matching, as the matching is not unique. Needless to say this strategy is near-superhuman as the required memory feat is on the order of the world record of recalling digits of pi. – orlp Jul 28 '20 at 02:01
  • The question this (vaguely) reminds me of is the following: * $n$ contestants play a game, where the host writes a (distinct) number on each contestant's forehead. The contestants can see the numbers on the other players' foreheads but not the one on their own. Then the contestants are given a pair gloves, one black, the other white. They must then (out of sight of each other) put the gloves on (assume a left/right symmetic structure). The host then arranges them on the stage in the order of the numbers, facing the crowd, and asks them to join hands with people on respective sides. – Jyrki Lahtonen Jul 28 '20 at 08:53
  • (cont'd) If each pair of joined hands has identically colored gloves the contestants collectively win the grand prize. If there is a single error, they all come out empty. The contestants have a few hours to agree on a strategy before the game begins, device one that guarantees success. This was discussed in XKCD fora, but those appear to be down now. My solution was based the contestants sorting each other in advance, and comparing the parity of that permutation with the one based on the numbers (IIRC as well as the parity of their place in the ordering). Probably has appeared elsewhere also. – Jyrki Lahtonen Jul 28 '20 at 08:57
  • 1
    I think, any permutation of $n=k!+k-1$ balls will contain at least one monotone block of $k$ consecutive balls, just a few preliminary results here and here. An extra indication/hint is required to "say" if it's decreasing or increasing. – rtybase Aug 09 '20 at 13:45
  • 4
    @rtybase when $k=3$ it could be $8,1,7,2,6,3,5,4$. I don't see a monotone block of three. – Jyrki Lahtonen Aug 09 '20 at 21:02
  • We can reduce the number of choices for the hidden permutation to $k$ as follows: divide the successive permutations into groups of size $k$; let $S_i$ be the set of permutations with starting index $i$ (mod $k$); we have $|S_i|=(k-1)!$. Map all permutations of $1,2,...,k$ injectively to elements of $\mathbb{Z}_{m}$ for $m=(k-1)!$, let $s_i$ be the sum of the elements of $S_i$ in $\mathbb{Z}_m$; hide the $s_i$th permutation of $S_i$ (any fixed $i$ works). By adding the sum of the remaining permutations of $S_i$ and subtracting $s_i$, we can find the hidden permutation modulo $(k-1)!$. – Aravind Aug 12 '20 at 07:40
  • If we have a sequence of $m$ elements of $\mathbb{Z}_m$, then hiding the $s$th element where $s$ is the sum of the elements lets the magician be able to find it. That was used above but doesn't work directly for the permutations problem; the catch is that successive permutations overlap. – Aravind Aug 12 '20 at 07:43
  • That shouldn't be "injective" but a $k-to-1$ map. – Aravind Aug 12 '20 at 07:52
  • If we map the permutations to a pair $(x,y)$ where $x \in \mathbb{Z}_{(k-1)!}$ and $y \in \mathbb{Z}_k$, then let $c$ be the sum of the $y$- coordinates of all the elements of $S_i$s, and we choose the column $S_c$, it could work. – Aravind Aug 12 '20 at 08:18

2 Answers2

4

This is a strategy that works in every case I checked, but its validity for all k needs to be proved. By his choice of placing the scarf, the assistant conveys information to the illusionist. There are $k!$ ways of placing the scarf, to the assistant.

Consider a random permutation ($a_1,a_2,...,a_n$) of {$1,2,...,n$}, that the audience chooses. The assistant looks at this arrangement and assigns a parity to it as follows:

  1. He takes the $k$-touple ($a_1,a_2,...,a_{k}$). He constructs a $k$-digit number (concatenation) from it as $$a_1a_2...a_{k}$$ He then calculates the rank of this number among all of its $k!$ permutations (lowest number gets rank 0 and highest gets rank $(k!-1)$). He assigns it a variable $$\boxed{x_1=(rank)}$$

  2. Assign $x_2$ to {$a_2,a_3,...,a_{k+1}$}. Similarly assign $x_3,x_4,...,$ and $x_{k!}$. Take that $a_i=a_{i+n}$

Compute the parity: $$p=mod\left(\sum_{i=1}^{k!} x_i,k!\right)$$

There are $k!$ values of $p$ possible: {$0,1,2,...,k!-1$}. Depending on the value of $p$ the assistant chooses where to place the scarf. (When $p=0$ he places over first $k!$ balls. When $p=1$ he places over second $k!$ balls,.. etc)

When the illusionist sees the obscured arrangement, he knows the value of $p$ by the position of the scarf. Although I haven't proved it yet, only one arrangement of the obscured balls gives this value of $p$. This strategy works for all cases of $k=2$ and many cases of $k=3$. But it is a behemoth to prove for general $(k,n)$.

  • 1
    I assume you mean $k$-tuples rather than $k!$-tuples? Also, I would write the parity equation as $p=\prod x_i$ to distinguish it from the concatenation $a_1 a_2 ... a_{k}$ (assuming that's what you meant). Also, can we get away with only computing $x_1, ..., x_{k!}$?

    I'm not convinced of your bold statement, but we can perhaps weaken it to "exactly one of the $k!$ choices yields a parity equal to $p$", which I am more inclined to believe. In any case, nice idea. I'm currently checking to see if it works for small $k$.

    – Andrew Szymczak Aug 12 '20 at 05:36
  • 1
    I found a counterexample for k=3. Both 1,2,3,[4,6,5],8,7 and 1,2,3,[5,4,6],8,7 have parity $p=3$ (using all $x_1, ..., x_n$). – Andrew Szymczak Aug 12 '20 at 06:59
  • @AndrewSzymczak I have changed the definition of parity:$$p=x_1+....+x_{k!}$$It gives no counter example for $k=3,p=3$. Maybe the strategy is complete now? –  Aug 12 '20 at 08:05
  • 5
    Then it doesn't work for $k=2$ (both 2,[1,3] and 2,[3,1] have parity 1). There are many other counterexamples for $k=3$ as well (for both definitions of parity). I think your solution is on the right track, but it's currently unclear to me how to fix it. – Andrew Szymczak Aug 12 '20 at 08:23
0

NOTE: I found counterexamples to the explicit $f$ I initially posted. I removed it but am leaving the rest of the answer up as a partial solution.


Notation and Remarks

Let $S_n$ denote the set of permutations of length $n$ and let $C_{n,k}$ be the set of covered permutations. For example, the permutation $12345678 \in S_8$ and $123\cdot\cdot\cdot78 \in C_{8,3}$. For brevity I often drop the subscripts.

The act of covering gives us a relation $\sim$ between the two sets, i.e. we say that $\pi \in S$ and $c \in C$ are compatible if $c$ is a covering of $\pi$. We can visualize this compatibility relation as a bipartite graph. For $k=2$ and $n=3$ we have:

$ \qquad \qquad \qquad \qquad \qquad \qquad $

We need to find an injective function $f : S_n \rightarrow C_{n,k}$ such that $\pi$ and $f(\pi)$ are always compatible. The assistant performs the function $f$ and the illusionist performs the inverse $f^{-1}$. As per the problem requirements, both $f$ and $f^{-1}$ need to be computable in poly(n) time for a given input. We note that given such an $f$, computing $f^{-1}$ is straightforward: given a covering $c$, we consider the compatible permutations. Among these, we choose the $\pi$ such that $f(\pi) = c$.

For $n = k! + k - 1$ we note that $|S_n| = |C_{n,k}| = n!\,$. We also note that each permutation is compatible with exactly $k!$ coverings and each covering is compatible with exactly $k!$ permutations. As OP mentioned, the Hall marriage theorem thus implies that a solution exists. We can find such a solution using a maximum matching algorithm on the bipartite graph. This is how @orlp found a solution for $k=3$ in the comments. However, the maximum matching algorithm computes $f$ for every permutation in poly(n!) time, where we instead need to compute $f$ for a single permutation in poly(n) time.