Maths Olympiad Prep

Library / /4 of 4

Combinatorics Difficulty 7.5 National Olympiad, round 2 Prove it Italy

Problem:

The robot "Mag-o-matic" manipulates 101 glasses, arranged in a row whose positions are numbered from 1 to 101. In each of the glasses there may or may not be a ball. The robot Mag-o-matic accepts only elementary instructions of the form (a;b,c)(a ; b, c), which it interprets as
"consider the glass in position aa: if it contains a ball, then swap the glasses that are in positions bb and cc (together with their possible contents), otherwise move on to the next instruction"
(it is understood that a,b,ca, b, c are integers between 1 and 101, with bb and cc different from each other, but not necessarily different from aa). A program is a finite sequence of elementary instructions, assigned in advance, that Mag-o-matic executes one after the other.
A subset S{0,1,2,,101}S \subseteq\{0,1,2, \ldots, 101\} is called identifiable if there exists a program that, starting from any initial configuration, produces a final configuration in which the glass in position 1 contains a ball if and only if the number of glasses containing a ball is an element of SS.

a. Prove that the subset of {0,1,,101}\{0,1, \ldots, 101\} consisting of the odd numbers is identifiable.

b. Determine all identifiable subsets of {0,1,,101}\{0,1, \ldots, 101\}.

Solution

Solution:

We solve directly the general case, showing that a subset SS is identifiable if and only if 0S0 \notin S and 101S101 \in S. At the end we will describe a shortcut that works in the odd case.

Necessary condition

Let us first show that the conditions 0S0 \notin S and 101S101 \in S are necessary. If, for contradiction, 0S0 \in S and at the beginning there are no balls in the glasses, no program can make a ball appear in the glass in position 1, as would instead be required. Symmetrically, if 101S101 \notin S and at the beginning all glasses contain a ball, then the configuration remains the same throughout the execution of the program, so that at the end there will certainly also be a ball in the glass in position 1, which should not happen in this case.

Sufficient condition

We now show that the conditions 0S0 \notin S and 101S101 \in S are sufficient. We denote by pp the number of glasses that contain a ball. As already observed, if p=0p=0 or p=101p=101, all possible instructions do not alter the configuration, which in both cases already satisfies the requirement from the start. In what follows we will therefore assume, without loss of generality, that 1p1001 \leq p \leq 100.

We say that the glasses are arranged in standard canonical position if the glasses with the ball occupy the positions from 1 to pp; we say that they are arranged in shifted canonical position if they occupy the positions from 2 to p+1p+1. We will show that there exists a program upon execution of which the final configuration will be the standard canonical one if pSp \in S, and will be the shifted canonical one if pSp \notin S (so in particular there will be a ball in the glass in position 1 if and only if pSp \in S).

We divide the required program into three subprograms. The first subprogram passes from the initial configuration to the standard canonical configuration. One way to achieve this is the following list of instructions.

- For every ii from 1 to 101 we execute the instruction (i;i,1)(i ; i, 1). If there is a ball somewhere, at the end there will also be a ball in the glass in position 1.
- For every ii from 2 to 101 we execute the instruction (i;i,2)(i ; i, 2). If there is at least one ball besides the one in the glass in position 1, at the end there will also be a ball in the glass in position 2.
- For every ii from 3 to 101 we execute the instruction (i;i,3)(i ; i, 3). If there is at least one ball besides those possibly present in the glasses in position 1 and 2, at the end there will also be a ball in the glass in position 3.
- Continuing in the same way we obtain the required result (more formally, this could be proved by induction).

The second subprogram passes from the standard canonical configuration to the shifted canonical one. To do this we execute the instruction (i;i,i+1)(i ; i, i+1) for every ii from 100 to 1, proceeding thus in reverse. These instructions do nothing as long as i>pi>p. When i=pi=p, the glass with the ball in position pp is moved to position p+1p+1, then the one in position p1p-1 is moved to position pp, and so on until the glass with the ball in position 1 is moved to position 2.

The third subprogram starts from the shifted canonical configuration. Given an integer ss, with 1s1001 \leq s \leq 100, we define ss-check as the pair of instructions (s+1;s+1,1)(s+1 ; s+1,1) and (s+2;s+1,1)(s+2 ; s+1,1) (in the case s=100s=100 the second instruction does not make sense, so only the first is executed). Let us examine the effect of an ss-check in three cases.

- Case 1. If we are in the shifted canonical configuration and sps \neq p, then essentially nothing happens. More precisely, if s>ps>p neither instruction finds the ball and so neither does anything, if s<ps<p both instructions find the ball and so the second one cancels the effect of the first.
- Case 2. If we are in the shifted canonical configuration and s=ps=p, then the first instruction moves the glass with the ball that is in position p+1p+1 (that is, the last glass with a ball in the row) to position 1, while the second instruction does not find the ball and so does nothing. Consequently, in this case the ss-check has the effect of passing from the shifted canonical configuration to the standard canonical configuration.
- Case 3. If we are in the standard canonical configuration and s<ps<p, then nothing happens, because the possible swaps take place between glasses that contain a ball.

We are now ready to describe the third subprogram, which executes the ss-check for all values sSs \in S, proceeding from the largest to the smallest. We have two possibilities.

- If pSp \notin S, then we are always in Case 1. Hence nothing ever happens, and the configuration remains the shifted canonical one, as expected in the case pSp \notin S.
- If pSp \in S, then nothing happens as long as values s>ps>p are being tested (Case 1), then when s=ps=p the configuration becomes the standard canonical one (Case 2), and then again nothing happens when the values s<ps<p are tested (Case 3). Hence at the end of the execution the configuration is the standard canonical one, as expected in the case pSp \in S.

Shortcut for the odd case

In the case where SS is the set of odd numbers from 1 to 101, it suffices to execute the first subprogram (the one that brings the glasses into the standard canonical configuration) and then execute the instruction (i;1,101)(i ; 1,101) for every ii from 2 to 101.

- If the number of balls is odd, the swap is executed an even number of times, and so at the end the standard canonical configuration remains, which has the ball in the glass in position 1.
- If the number of balls is even, the swap is executed an odd number of times, and so at the end the glass in position 1 will be the one that in the standard canonical configuration was in position 101, which was empty (since pp is even).

Remark

In the solution of the general case one can pass directly from the initial configuration to the shifted canonical one, without going through the standard canonical one. It suffices to execute a version of the first subprogram in which all the indices are cyclically shifted 12310010111 \rightarrow 2 \rightarrow 3 \rightarrow \ldots \rightarrow 100 \rightarrow 101 \rightarrow 1, as if the row started from position 2 to end at position 1 "after going around".

Want a route through all this instead of an archive? The track puts 2,000 problems in a working order, from AMC 10 level to the IMO shortlist.

Source: MathNet, licensed CC-BY-4.0. Statement translated into English from it; metadata (topic, difficulty) added by this project.