We will give an algorithmic strategy, recursive on the factorization of the table size n, for Magnus to visit positions in rounds. We begin with the cases where n is a power of two or is prime.
2.2. When n is prime
Let be prime. Since n is prime, by Theorem 1 we have that . We will prove that there is a strategy for Magnus to visit at least positions in at most rounds.
Our key idea (which coincides with the idea in [
3]) behind Magnus’ strategy is as follows. Let
K denote the current position of the token, and let
denote the set of unvisited positions. Notice that if
K is equidistant (with distance
d) from two different positions in
, then Magnus can choose magnitude
d and, regardless of Derek’s choice, the token will move to one of those positions. We will use this fact by constructing a nested sequence of sets
with the property that for
, each position in
is equidistant from a pair of positions in
. Then, if
for some
i, Magnus can move the token to a position in
in one round. Since
, Magnus can always move the token to an unvisited position in at most
rounds. This idea may be applied repeatedly, with the set of unvisited positions
decreasing in size by one each time. We will show that in this manner
positions can be visited.
We begin with some necessary standard notations and background from additive number theory. Let
A and
B be two subsets of
. Then the
sumset of
A and
B is
and a
q-dilate of
A is
We now define a map on the family of subsets of .
Definition 1. Let , . The set of all middles between pairs of elements of A is defined byWhen n is odd, exists and thenWe will use the notation to denote the recursive application to A of the map M, i times, and define . For example, . Thus , and for each pair of points , all points equidistant from x and y are contained in . When n is odd, there is a unique midpoint equidistant from x and y.
Remark 1. If n is odd, and A is the arithmetic progression for some , and m, then and is consequently easy to compute.
Bellow, we use the following well known Cauchy-Davenport Theorem [
8,
9].
Theorem 3. If p is a prime, and are two non-empty subsets of , then Lemma 1. Let be prime and . Then for any positive integer i, Proof. Since n is odd, and so . By Theorem 3, . Thus the lemma holds for .
Applying the above inequality recursively, we have that
where
is the
i-th term of the recurrence relation
By induction, it is easy to prove that for any positive integer
i,
. This is trivially true for
. Assuming the inductive hypothesis for
, it follows that
Lemma 2. Let be prime, and , . Then . Note that it is possible to have for .
Proof. The inclusions follow from the definition of the map M.
For , we have . Then by Lemma 1, , and so . ☐
Lemma 3. Let be prime, and let , . Then if for some , there exist two distinct positions such that z is equidistant from x and y.
Proof. Since , by definition of the map M there exist positions such that . Thus z is equidistant from x and y. Since , x and y are distinct. ☐
Thus, given a set of unvisited positions , we are able to construct a nested sequence of sets with the desired property. While , Lemmas 2 and 3 guarantee that Magnus can move the token to an unvisited position. By repeated use of this idea until , Magnus can visit all but one position. It remains to show that this takes at most rounds.
Remark 2. Notice that Derek controls which single position remains unvisited. We will use this fact when we give the strategy for composite table sizes in Section 2.3. Theorem 4. Let the table size be prime. Then Magnus can visit positions in at most rounds.
Proof. Throughout this proof we will use to denote the remaining set of unvisited positions, and K the current position of the token. At the beginning of the game, , since the token initially occupies a position. Let .
In order to count the number of rounds required, we use the following idea. Let
k be a non-negative integer. By equation (
1) in Lemma 1, if
, then
= n. It follows that
, and so Magnus can move the token to an unvisited position in at most
k rounds.
Initially, , so and only one round is required to move the token to an unvisited position. Magnus may continue to visit unvisited positions at the cost of one round per position until . Thus he visits positions in rounds.
Similarly, when , he may visit positions at the cost of at most two rounds per position, for a total of at most rounds.
Eventually,
, and he must stop. We thus have that the total number of rounds is at most
2.3. When n is composite
Let
n be composite, and let
p be the smallest odd prime factor of
n. Then by Theorem 1 we have
. We will give a recursive strategy for Magnus, proving that he can visit at least
positions in at most
rounds. The better bound on the number of rounds is obtained using the recursive strategy from [
1].
We present the strategy in two phases. In the first phase of the strategy, Magnus partitions the table into
p congruence classes each of size
, moves the token to
of these classes using a strategy based on
Section 2.2, and in each of these
classes recursively applies this two-phase strategy to visit at least
positions within the class. Thus at the end of the first phase, Magnus will have visited at least
positions, and at most
positions. If Magnus succeeds in visiting
positions then the second phase is not needed. Otherwise, he uses a second technique to visit some of the unvisited positions left over from the first phase, bringing the total number of visited positions up to
.
2.3.1. The first phase: Decomposition into classes, and recursive visitation
Lemma 4 (Decomposition)
. Let the table size be , where a and b are integers greater than 1. Suppose that on a table of size a (resp. b), Magnus has a strategy α (resp. β) to visit (resp.) positions in (resp. ) rounds. Then on the table of size n, Magnus is able to visit positions in rounds.
Proof. We partition the table positions (
i.e., the elements of
) into the
b congruence classes modulo
b, each of size
a:
We first note that Magnus can restrict his play to positions in a particular class. Let K denote the current position of the token, and suppose that for some . Magnus can then play as follows on an imaginary table of size a whose positions are the elements of . On each round, Magnus employs strategy α to calculate a magnitude ℓ as if the table size were a, but then chooses as the actual magnitude to use. Then the new position of the token will be , and so the token will remain within the class.
Magnus’ overall strategy will be to repeatedly move the token to an unvisited class, and then, by restricting his play to positions within that class, use strategy α to visit positions within that class in rounds.
Now suppose that for some i, and notice that for any magnitude ℓ, . Magnus can use this idea to play on an imaginary table of size b whose positions correspond to the b congruence classes. By employing strategy β on this imaginary table, Magnus will visit different classes in rounds. Each time the token lands in an unvisited class, Magnus temporarily restricts his play to that class, and employs strategy α until he has visited positions within that class. He then continues with strategy β until he reaches another unvisited class.
Since Magnus can visit classes in rounds, and can visit positions in rounds within each class, the total number of positions visited will be and the total number of rounds will be . ☐
Magnus applies the Decomposition Lemma (Lemma 4) by letting
, where
p is the smallest odd prime factor of
n, and partitioning the table into
p congruence classes modulo
p, each of size
. He then proceeds as in the proof of the lemma, letting strategy
β be the technique for playing on a table of prime size from
Section 2.2. Theorem 4 then guarantees that he will visit
congruence classes. As he visits each class, he restricts his play to it and, depending on the size of the class, chooses one of the following strategies to be strategy
α:
- Case 1)
If the size is a power of two, he uses the strategy from
Section 2.1. Then by Theorem 2 he will visit all positions in the class.
- Case 2)
If the size is a prime, he uses the strategy from
Section 2.2. Then by Theorem 4 he will visit all but one position in the class.
- Case 3)
Otherwise, if the size is composite, he uses the strategy being described here (
Section 2.3), applied recursively.
We will use the terminology exploring a class to refer to the process of restricting play to a class and choosing an appropriate strategy α. We will also say that a class that has been visited in this fashion has been explored.
See phase 1 of algorithm 1, below, for a pseudo-code description of this strategy.
Recall that Magnus’ goal is to visit positions (in as few rounds as possible). Since only classes have been visited, Magnus will have visited positions only if he visited all positions in each of the classes. But this is possible only when for some integer k, since only in case 1 does Magnus visit every position in a class. So for most table sizes n, the first phase is insufficient for Magnus to visit positions. We solve this issue by visiting in the second phase some of the leftover unvisited positions, either in the classes that Magnus has explored, or in the one class that was never visited.
2.3.2. The second phase: Visiting leftover unvisited positions
Here, Magnus’ strategy is the same as in Phase 2 from [
1]. At the end of the first phase, there is one unvisited class, which we denote
, and
explored classes, which we denote
. Inductively we assume that on a table of size
Magnus can visit
positions in at most
rounds. (This will follow from the inductive hypothesis in our proof in
Section 2.3.3.) It follows that at the end of the first phase at least
positions have been visited in each of the explored classes. Without loss of generality we assume the worst case, in which exactly
positions were visited. Let
be the second smallest odd prime factor of
n. By Theorem 1,
. Then in each explored class,
positions remain unvisited.
We consider two ways in which Magnus can bring the total number of visited positions up to . If Magnus visits all leftover positions in each of the explored classes, then he will have visited every position in classes for a total of positions. If instead he visits positions of , then he will have visited all but positions in every class, leaving unvisited positions in total. But this means that he has visited positions.
Therefore Magnus’ goal will be to either move the token to the class , at which point he can recursively explore that class, or to visit all unvisited positions in .
Notice that since are the p distinct elements of , we have that are also distinct in . Therefore, up to re-ordering, we may write the explored classes as . Let be an unvisited position for some , and suppose for the moment that Magnus is able to move the token to a position . Consider what happens when Magnus chooses the magnitude . If Derek chooses the positive (clockwise) direction, then the token moves to , and Magnus visits the unvisited position. Otherwise, the token moves to .
Using the above idea, Magnus has the following strategy. As in the first phase, he uses the technique from
Section 2.2 to play on an imaginary table of size
p, where each position on this table corresponds to a class. Then by Theorem 4 he will visit
classes. If at any time he visits the class
, he recursively explores it and is done. Otherwise, he will visit each of the
explored classes,
. Each time he visits a class
he has the opportunity to visit an unvisited position in the class
.
By repeating this process times (for the unvisited positions in each explored class) he will eventually visit all unvisited positions in every explored class.
We give Magnus’ strategy in pseudo-code in algorithm 1, below. It remains to prove that this strategy visits at least positions in at most rounds.
Algorithm 1 Recursive algorithm for exploring a table of size n. |
- Require:
p is the smallest prime factor of n. - Require:
The table is partitioned into p congruence classes modulo p, , each of size .- - 1:
//Phase 1: Visit congruence classes, and recursively explore each one. - 2:
//In the below loop, Magnus plays on an imaginary table of size p where each position corresponds to a class, as in the Decomposition Lemma (Lemma 4). The strategy from Section 2.2 is used as strategy β in the Lemma. - 3:
while fewer than classes have been visited do - 4:
Move to an unvisited class . //May require multiple rounds. - 5:
//Now choose strategy α. - 6:
if for some integer k then - 7:
Use the strategy from Section 2.1 to visit all positions of in rounds. - 8:
else if , where q is prime then - 9:
Use the strategy from Section 2.2 to visit positions of in at most rounds. - 10:
else - 11:
Recursively apply this algorithm to the class . - 12:
end if - 13:
end while - 14:
//Phase 2: Visit remaining unvisited positions. - 15:
//We denote the unvisited class , and the explored classes . - 16:
while there are unvisited positions in do - 17:
Mark the classes as not yet visited in this iteration. - 18:
//In the below inner loop, Magnus again plays on an imaginary table of size p where each position corresponds to a class, using the strategy from Section 2.2. - 19:
while more than one class remains marked do - 20:
Move to a marked class for some . //May require multiple rounds. - 21:
Choose the magnitude so that the token will move to either or an unvisited position in . //Token moves in one round. - 22:
if the token is in then - 23:
Recursively apply this algorithm to the class , and stop. - 24:
else - 25:
Unmark the class . - 26:
end if - 27:
end while - 28:
end while
|
2.3.3. Proof of the strategy
We will prove that Magnus’ strategy allows him to visit at least
positions in at most
rounds. First notice that Derek controls whether the token ever reaches
. For in
Section 2.2, Derek controls which position remains unvisited (Remark 2), and so here controls which class remains unvisited (on the imaginary table whose positions are classes). Furthermore, each time the token is in a class
for some
i, Derek controls whether the token moves to
.
We will thus make the assumption that Magnus visits if and only if he does not visit any of the leftover unvisited positions in the explored classes. This assumption is justified by Derek’s primary goal to minimize the number of positions visited by Magnus. For if Magnus is allowed to visit both and at least one leftover unvisited position in the explored classes, the total number of visited positions will be greater than and since , the total number of visited positions will be greater than .
Theorem 5. Let where p is the smallest odd prime factor of n. If Derek does not allow for more than visited positions and therefore is consistent in his choices (as stated above), then there exists a strategy for Magnus to visit at least positions in at most rounds.
Proof. Let
s denote the number of odd prime factors of
n. We will prove by induction on
s that Magnus visits at least
positions in at most
rounds.
- Base case 1)
, . Then by Theorem 2 Magnus visits positions in rounds.
- Base case 2)
, p prime. Then by Theorem 4 Magnus visits positions in at most rounds.
- Base case 3)
, , p prime. Then in the first phase Magnus visits all positions in each of classes. He requires at most rounds to visit the classes, and to explore each class, for a total of at most rounds. No second phase is needed.
We now let and assume the following inductive hypothesis: If n has odd prime factors then Magnus can visit at least positions in at most rounds.
Let , where are prime and listed in increasing order. Then there are classes, each of size . Magnus’ goal is to visit at least positions, or equivalently, to leave at most positions unvisited.
In the first phase of the algorithm, Magnus visits classes and recursively applies the algorithm to explore within each class. Then by the inductive hypothesis, he leaves at most unvisited positions in each explored class. Without loss of generality, we assume the worst case of unvisited positions. Furthermore, has not been visited, so a total of positions remain unvisited.
Magnus requires at most rounds to visit the classes (Theorem 4 as applied in the first phase). Furthermore, by the inductive hypothesis he requires at most rounds to recursively explore each class. So by lemma 4, at the end of the first phase, at most rounds have occurred.
For the second phase we consider two cases.
- Case A)
Magnus never visits
. Then in order to achieve his goal Magnus must visit all of the leftover unvisited positions in the
explored classes. This requires that he repeatedly visit the explored classes
times (using the strategy from
Section 2.2). Each time, he takes at most
rounds,
from Theorem 4, and
from the one round to move from
to
for each
. Thus a total of at most
rounds are required for the second phase.
- Case B)
Magnus visits , but no leftover unvisited positions in the explored classes. By the inductive hypothesis, Magnus leaves at most positions unvisited in . Since this is also true of the explored classes, a total of at most positions remain unvisited, and Magnus achieves his goal.
We now count how many rounds this requires. At the end of the first phase, at most one round is required to move the token to , for if the token is not already in then it is in for some i. By the inductive hypothesis Magnus requires at most rounds to explore . Thus a total of at most rounds are required for the second phase.
In both cases, Magnus visits at least positions, and a simple calculation shows that he achieves this goal in at most rounds. ☐
2.3.4. Efficiency of the strategy
In order for Magnus to calculate magnitudes in the above algorithm, he must know at each round the smallest integer
k such that
(see the proof of Theorem 4 in
Section 2.2). In general, the only way we know to determine this is to consecutively compute
until we reach
. Furthermore, Lemma 3 requires that as we calculate these sets we record for each position
(
) a pair of positions
such that
z is equidistant from
x and
y. With a naive algorithm, this is computationally time consuming. Given a set
S of size
m, computing
requires calculations of
for each
, and so is
.