An O(n)-Round Strategy for the Magnus-Derek Game

We analyze further the Magnus-Derek game, a two-player game played on a round table with n positions. The players jointly control the movement of a token. One player, Magnus, aims to maximize the number of positions visited while minimizing the number of rounds. The other player, Derek, attempts to minimize the number of visited positions. We present a new strategy for Magnus that succeeds in visiting the maximal number of positions in 3(n – 1) rounds, which is the optimal number of rounds up to a constant factor.


Introduction
In this paper we analyze further the Magnus-Derek game, a two-player game introduced in [1].The game is played on a circular table with n positions labeled consecutively from 0 to n − 1 in a clockwise direction.A single token is initially placed at position 0. A round consists of the first player, Magnus (from magnitude) choosing an integer magnitude 0 < ≤ n 2 , followed by the second player, Derek (from direction) choosing whether the token will move clockwise or counter-clockwise.The token is then moved positions in the chosen direction.Magnus's primary goal is to maximize the total number of distinct positions visited by the token over the course of the game (and secondarily, to minimize the number of rounds), while Derek main aim is to minimize the number of positions visited.These goals are natural since for all n not exact power of 2, Derek has a strategy to prevent the token from visiting some of the positions [1].For brevity, we will skip from now the word distinct in all expressions of type "maximize the total number of distinct positions visited." In our analysis we will use Z n = {0, 1, 2, . . ., n − 1} to represent the table of size n.Let K ∈ Z n denote the position of the token at the beginning of a round.The round then consists of Magnus choosing a magnitude 0 < ≤ n 2 , Derek choosing a direction + or − (where the positive direction corresponds to "clockwise"), and the token moving to (K ± ) mod n.
In [1,2], the following function on the set of positive integers was used.Let n > 0 be an integer.Then • n otherwise, where p is the smallest odd prime factor of n.
In [1] (and subsequently with a shorter proof in [2]), the following theorem was obtained.
• Derek has a strategy to prevent the token from visiting more than f * (n) positions no matter how long the game is played.
• Magnus has a strategy to ensure the token visits at least f * (n) positions.
One of the strategies previously given for Magnus by Nedev and Muthukrishnan requires O(n 2 ) rounds [1].A recent paper by Hurkens, Pendavingh, and Woeginger gives an O(n log(n))-round strategy [3].In this paper, we will show that Magnus can visit f * (n) positions in 3(n − 1) rounds, the optimal number of rounds up to a constant factor.Although some of the basic ideas in the two papers are the same, we wrote our paper well before the paper of Hurkens, Pendavingh, and Woeginger was published [4], and our results were found independently from theirs .
Our strategy for Magnus requires that he know the factorization of n.To our knowledge, this is the first game in which the ability to factor conveys an advantage to a player.In another variant of the game called the Vector game [5], the players' goals are reversed: Magnus wants to minimize the set of occupied positions, while Derek aims to maximize the number of positions visited.The ability to factor can also give a crucial advantage to a player here.Moreover the analysis of this second variant of the game is also not completely done yet; it created several new open problems (see [5,6]).
As mentioned in [1], the sequence {f ) diverges non-monotonically and non-linearly to ∞.This sequence has not previously appeared in the Encyclopedia of Integer Sequences [7].

An O(n)-Round Strategy for Magnus
We will give an algorithmic strategy, recursive on the factorization of the table size n, for Magnus to visit f * (n) positions in O(n) rounds.We begin with the cases where n is a power of two or is prime.

When n is a power of two
An optimal strategy was given in [1] for when the table size is a power of two.We quote only the result here: Theorem 2. (from [1]) If n = 2 k for some integer k, then f * (n) = n, and Magnus can visit all positions in n − 1 rounds, regardless of Derek's strategy.

When n is prime
Let n > 2 be prime.Since n is prime, by Theorem 1 we have that f * (n) = n−1 n n = n − 1.We will prove that there is a strategy for Magnus to visit at least n − 1 positions in at most 2(n − 1) 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 A denote the set of unvisited positions.Notice that if K is equidistant (with distance d) from two different positions in A, 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 for some i, Magnus can move the token to a position in M (i−1) (A) in one round.Since K ∈ Z n = M ( log 2 (n) ) (A), Magnus can always move the token to an unvisited position in at most log 2 (n) rounds.This idea may be applied repeatedly, with the set of unvisited positions A decreasing in size by one each time.We will show that in this manner n − 1 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 Z n .Then the sumset of A and B is and a q-dilate of A is q * A := {e ∈ Z n : there exists a ∈ A such that e ≡ qa (mod n)}.
We now define a map on the family of subsets of Z n .
The set of all middles between pairs of elements of A is defined by When n is odd, 2 −1 ∈ Z n exists and then We will use the notation M (i) (A) to denote the recursive application to A of the map M , i times, and define Thus A ⊆ M (A), and for each pair of points x, y ∈ A, all points equidistant from x and y are contained in M (A).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 {a 0 + iδ : 0 ≤ i ≤ m − 1} ⊆ Z n for some a 0 , δ, and m, then (1) . Thus the lemma holds for i = 1.
Applying the above inequality recursively, we have that By induction, it is easy to prove that for any positive integer i, a i = 2 i (|A| − 1) + 1.This is trivially true for i = 1.Assuming the inductive hypothesis for i − 1, it follows that Proof.The inclusions follow from the definition of the map M .
For |A| ≥ 2, we have Then by Lemma 1, |M ( log 2 (n) ) (A)| = n, and so Lemma 3. Let n > 2 be prime, and let A ⊆ Z n , |A| ≥ 2. Then if z ∈ M (i) (A) \ M (i−1) (A) for some i > 0, there exist two distinct positions x, y ∈ M (i−1) (A) such that z is equidistant from x and y.
, by definition of the map M there exist positions x, y ∈ M (i−1) (A) such that z = 2 −1 (x + y).Thus z is equidistant from x and y.Since z ∈ M (i−1) (A), x and y are distinct.Thus, given a set of unvisited positions A, we are able to construct a nested sequence of sets with the desired property.While |A| ≥ 2, Lemmas 2 and 3 guarantee that Magnus can move the token to an unvisited position.By repeated use of this idea until |A| = 1, Magnus can visit all but one position.It remains to show that this takes at most 2(n − 1) 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.In order to count the number of rounds required, we use the following idea.Let k be a non-negative integer.By equation It follows that M (k) (A) = Z n , and so Magnus can move the token to an unvisited position in at most k rounds. Initially, +1, so M (1) (A) = Z n 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 |A| < n−1 2 1 +1.Thus he visits n−1 rounds.
Similarly, when n−1 + 1, he may visit n−1 positions at the cost of at most two rounds per position, for a total of at most 2 × n−1 , and he must stop.We thus have that the total number of rounds is at most (by telescoping)

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 f * (n) = p−1 p n.We will give a recursive strategy for Magnus, proving that he can visit at least f * (n) positions in at most 3(n − 1) 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 n p , moves the token to p − 1 of these classes using a strategy based on Section 2.2, and in each of these p − 1 classes recursively applies this two-phase strategy to visit at least f * ( n p ) positions within the class.Thus at the end of the first phase, Magnus will have visited at least (p − 1)f * ( n p ) positions, and at most (p − 1) n p = f * (n) positions.If Magnus succeeds in visiting f * (n) 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 f * (n).Proof.We partition the table positions (i.e., the elements of Z n ) 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 K ∈ [i] b for some 0 ≤ i ≤ b − 1. Magnus can then play as follows on an imaginary table of size a whose positions are the elements of [i] b .On each round, Magnus employs strategy α to calculate a magnitude as if the table size were a, but then chooses b as the actual magnitude to use.Then the new position of the token will be K ± b ∈ [i] b , 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 f * (a) positions within that class in r(a) rounds.Now suppose that K ∈ [i] b for some i, and notice that for any magnitude , Magnus applies the Decomposition Lemma (Lemma 4) by letting n = pm, where p is the smallest odd prime factor of n, and partitioning the table into p congruence classes modulo p, each of size n p .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 p − 1 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.

Proof of the strategy
We will prove that Magnus' strategy allows him to visit at least f * (n) positions in at most 3(n − 1) rounds.First notice that Derek controls whether the token ever reaches [γ] p .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 [2 −1 (δ i + γ)] p for some i, Derek controls whether the token moves to [γ] p .
We will thus make the assumption that Magnus visits [γ] p 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 [γ] p and at least one leftover unvisited position in the explored classes, the total number of visited positions will be greater than pf * (n/p) and since f * (n/p) ≥ (p−1)(n/p) p , the total number of visited positions will be greater than f * (n).Let n = 2 k p 1 p 2 For the second phase we consider two cases.
Case A) Magnus never visits [γ] p 1 .Then in order to achieve his goal Magnus must visit all of the leftover unvisited positions in the p 1 − 1 explored classes.This requires that he repeatedly visit the explored classes n p 1 p 2 times (using the strategy from Section 2.2).Each time, he takes at most 3(p 1 − 1) rounds, 2(p 1 − 1) from Theorem 4, and p 1 − 1 from the one round to move from 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 [γ] p 1 , for if the token is not already in [γ] p 1 then it is in [2 −1 (δ i + γ)] p 1 for some i.By the inductive hypothesis Magnus requires at most 3( n p 1 − 1) rounds to explore [γ] p 1 .Thus a total of at most 1 + 3( n p 1 − 1) rounds are required for the second phase.
In both cases, Magnus visits at least f * (n) positions, and a simple calculation shows that he achieves this goal in at most 3(n − 1) rounds.

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 M (k) (A) = Z n (see the proof of Theorem 4 in Section 2.2).In general, the only way we know to determine this is to consecutively compute A, M (A), M (2) (A), . . .until we reach Z n .Furthermore, Lemma 3 requires that as we calculate these sets we record for each position z ∈ M (i) (A) \ M (i−1) (A) (1 ≤ i ≤ j) a pair of positions x, y ∈ M (i−1) (A) 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 M (S) requires calculations of 2 −1 (x + y) (mod m) for each x, y ∈ S, and so is O(m 2 ).

Open Problems
We propose several open problems for future study.1.What is the most efficient way for Magnus to compute magnitudes in this strategy?2. Can we prove a tighter upper bound on the number of rounds required by Magnus?We conjecture that there is a strategy for Magnus to visit f * (n) positions in at most n + c rounds, where c is a small constant.

Theorem 3 .Lemma 1 .
and is consequently easy to compute.Bellow, we use the following well known Cauchy-Davenport Theorem [8,9].If p is a prime, and A, B are two non-empty subsets of Z p , then |A + B| ≥ min{p, (|A| + |B| − 1} Let n > 2 be prime and A ⊆ Z n .Then for any positive integer i,

Theorem 4 .
Let the table size n > 2 be prime.Then Magnus can visit f * (n) = n − 1 positions in at most 2(n − 1) rounds.Proof.Throughout this proof we will use A to denote the remaining set of unvisited positions, and K the current position of the token.At the beginning of the game, |A| = n − 1, since the token initially occupies a position.Let h = log 2 (n) .

2. 3 . 1 .
The first phase: Decomposition into classes, and recursive visitation Lemma 4 (Decomposition).Let the table size be n = ab, 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 f * (a) (resp.f* (b)) positions in r(a) (resp.r(b)) rounds.Then on the table of size n, Magnus is able to visit f * (a)f * (b) positions in r(b) + r(a)f * (b) rounds.
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 f * (b) different classes in r(b) 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 f * (a) positions within that class.He then continues with strategy β until he reaches another unvisited class.Since Magnus can visit f * (b) classes in r(b) rounds, and can visit f * (a) positions in r(a) rounds within each class, the total number of positions visited will be f * (a)f * (b) and the total number of rounds will be r(b) + r(a)f * (b).

Theorem 5 .
Let n = pm where p is the smallest odd prime factor of n.If Derek does not allow for more than f * (n) visited positions and therefore is consistent in his choices (as stated above), then there exists a strategy for Magnus to visit at least f * (n) = p−1 p n positions in at most 3(n − 1) 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 f * (n) positions in at most 3(n − 1) rounds.Base case 1) n = 2 k , k > 0. Then by Theorem 2 Magnus visits f * (n) = 2 k positions in n−1 ≤ 3(n−1) rounds.Base case 2) n = p, p prime.Then by Theorem 4 Magnus visits f * (n) = p − 1 positions in at most 2(p − 1) ≤ 3(n − 1) rounds.Base case 3) n = 2 k p, k > 0, p prime.Then in the first phase Magnus visits all 2 k positions in each of p − 1 classes.He requires at most 2(p − 1) rounds to visit the classes, and 2 k − 1 to explore each class, for a total of at most 2(p − 1) + (p − 1)(2 k − 1) ≤ 3(n − 1) rounds.No second phase is needed.We now let s > 1 and assume the following inductive hypothesis: If n has s − 1 odd prime factors then Magnus can visit at least f * (n) positions in at most 3(n − 1) rounds.
• • • p s , where p 1 , p 2 , . . ., p s are prime and listed in increasing order.Then there are p 1 classes, each of size n p 1 .Magnus' goal is to visit at least f * (n) = p 1 −1 So by lemma 4, at the end of the first phase, at most 2(p 1 − 1) + 3(p 1 − 1)( n p 1 − 1) rounds have occurred.
unvisited positions in each explored class.Without loss of generality, we assume the worst case of n p 1 p 2 unvisited positions.Furthermore, [γ] p 1 has not been visited, so a total of (p 1 − 1) n p 1 p 2 + n p 1 positions remain unvisited.Magnus requires at most 2(p 1 − 1) rounds to visit the p 1 − 1 classes (Theorem 4 as applied in the first phase).Furthermore, by the inductive hypothesis he requires at most 3( n p 1 − 1) rounds to recursively explore each class.
Thus a total of at most 3 n p 1 p 2 (p 1 − 1) rounds are required for the second phase.Case B) Magnus visits [γ] p 1 , but no leftover unvisited positions in the explored classes.By the inductive hypothesis, Magnus leaves at most n p 1 p 2 positions unvisited in [γ] p 1 .Since this is also true of the explored classes, a total of at most p 1 n p 1 p 2 ≤ n p 1 positions remain unvisited, and Magnus achieves his goal.