# An illusionist and their assistant are about to perform the following magic trick

Let $$kk$$ be a positive integer. A spectator is given $$n=k!+k−1n=k!+k−1$$ balls numbered $$1,2,\dotsc,n1,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 $$kk$$ consecutive balls, and covers them under their scarf. Then the illusionist looks at the newly obscured sequence and guesses the precise order of the $$kk$$ 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 $$kk$$ and the obscured sequence as input and then runs in time polynomial in $$nn$$. A mere proof that an appropriate strategy exists does not qualify as a complete solution.)

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

I can prove that such a strategy must exist:

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

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

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

Update: 2020. 12. 20.

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!k!$$ ways of placing the scarf, to the assistant.

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

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

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

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

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

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