At the entrance to a cave is a rotating round table. On top of the table are $n$ identical barrels, evenly spaced along its circumference. Inside each barrel is a herring either with its head up or its head down. In a move, Ali Baba chooses from $1$ to $n$ of the barrels and turns them upside down. Then the table spins around. When it stops, it is impossible to tell which barrels have been turned over. The cave will open if the heads of the herrings in all $n$ barrels are up or are all down. Determine all values of $n$ for which Ali Baba can open the cave in a finite number of moves. (11 points)
Problem
Source:
Tags: algorithm, induction
03.09.2010 13:56
It's e very difficult problem For same problem solution takes one chapter in the book $Mathematical Gardner$:) Have you official solution to this problem?
03.09.2010 14:30
OK, Official Solution : Answer: As $N = 2^k, k = 0, 1, 2,\cdots.$ Let us replace barrels by digits $"0"$s and $"1"$s arranged in a circular way. (i) Let $N \neq 2^k, k = 0, 1, 2,\cdots.$ Let us prove that without good luck Ali Baba never opens the cave. We can assume that we are playing against Ali Baba, spinning the circle, and he tells us in advance where he going to change digits in each round, including the first one. Assume $N$ is odd. Let us place digits $"0"$s and $"1"$s to prevent Ali Baba win in the first round. This means that after his first move (which we know) there are both digits $"0"$s and $"1"$s. Let Ali-Baba at some round select $k$ positions. He wins at this round if and only if these $k$ positions coincide either with the set of all $"0"$s or with the set of all $"1"$s. But the number of $"0"$s is not equal to the number of $"1"$s as their sum is odd and therefore at least one of these numbers differs from $k$. Then moving such digit to one of selected $k$ positions we prevent Ali Baba from winning at this round. (ii) The case when $N$ is even but has an odd factor $m$ could be reduced to the previous one. Let us mark on the circle m equidistant positions and forget about all others. Then using the same method as in (i) we can prevent Ali Baba from making digits on these $m$ position equal. (iii) Algorithm of Ali Baba' win for $N = 2^k$ we construct by induction. The base of induction $k = 1$ is trivial. Let Ali Baba has algorithm $A_m$ for $m$ barrels. Let us construct $A_{2m}$. All positions for $N=2m$ we split into $m$ pairs of opposite positions . Then we establish one-to-one correspondence between pairs for $N = 2m$ and positions for $N = m.$ First, let us consider the special cases. (a) Assume that in each pair digits are the same. Then we can apply $A_m$ (with pairs instead of positions). If we unlock the cave in first case ($N = m$) then the cave will be unlocked in second case. (b) Consider the parity of the sum in each pair. Assume that all parities are the same. Let us apply algorithm $A_m$; if cave is unlocked then all the parities were odd. However, changing both digits in a pair we do not change the parity of pair, therefore, all the parities remain odd. Let us change exactly one digit in each pair (call this operation $D$). Then all the parities became even. Applying $A_m$ one more time we unlock the cave. Let us call this algorithm $B$. (c) Consider a general case. Let us apply algorithm $A_m$ in the different way: our goal is to make all parities equal. So, we apply $A_m$ but this time changing in each pair only one digit. Call this algorithm $C$. It guarantees that at some step all parities will coincide. However, we do not know when it will happen. So, we apply the following trick: after each step of applying $C$ we apply $B$ and then $D$. If after $C$ the parities coincide then $B$ unlocks the cave. Otherwise, $BD$ does not change parities, so parities after $C$ and $CBD$ are the same. As $\underbrace{C...C}_{j \text{ times}}$ makes parities equal and since $\underbrace{CBD...CBD}_{j \text{ times}}$ makes parities equal as well then $\underbrace{CBD...CBD}_{j-1 \text{ times}}CB$ unlocks the cave.
03.09.2010 14:39
In book witch i said next problem: Ali-Baba use exactly $k$ hands but he ca chose turn barrel or not turn barrel. Needs to prove that minimum $k$ for which Ali-Baba can win, equals $[(1-\frac{1}{p})n]$ , where $p$ is maximum prime divisor of $n$. I have book only in Russian P.S. thanks the prove