1 Introduction
Combinatorial game theory is not only an interesting theory on its own, it links to many other fields of mathematics. For example, Conway and Sloane showed in
conway1986lexicographic that the “losing positions” of some combinatorial games give linear error detecting and correcting codes. Using this view of these codes as combinatorial games, Fraenkel and Rahat showed in fraenkel2002complexity that the codes can be computed in polynomial time and memory.In this paper we demonstrate a similar application of combinatorial game theory to coding: we show that the optimal play (when both players apply their only nonlosing strategies) of a certain combinatorial game constitutes the well known prefermax De Bruijn sequence (defined below). Then, parallel to the work of Fraenkel and Rahat in fraenkel2002complexity , we also show how nonlosing strategies can be computed in linear time and memory, yielding an efficiently computable shiftrule (mapping a state of a shift register to its follower) for the sequence.
We use lowercase Greek letters to denote symbols in the alphabet and lowercase Latin letters to denote words in , except for and which represent natural numbers and indexes.
2 The prefmax De Bruijn sequence and the corresponding Hamiltonian cycle in the De Bruijn graph
A De Bruijn sequence of order on the alphabet is a cyclic sequence of length such that every possible string of length (member of ) appears exactly once as a substring bruijn1946combinatorial .
The directed De Bruijn graph of order over the alphabet (also described in bruijn1946combinatorial ) is the graph whose vertexes are the strings of length over the alphabet (i.e. the set ) and whose edges are such that each vertex is connected with a directed edge to all the vertexes in .
There is a onetoone correspondence between De Bruijn sequences and Hamiltonian cycles in the De Bruijn graph of the same order and alphabet, described in bruijn1946combinatorial and it is as follows:

If, for each , , and is an Hamiltonian cycle then is a De Bruijn sequence.

A Hamiltonian cycle can be constructed from a De Bruijn sequence by visiting the vertex , then and so on, until we return to where we started.
In this paper we focus on a specific Hamiltonian cycle in the De Bruijn graph called the prefermax cycle (and the corresponding De Bruijn sequence) defined as follows. For simplicity, we only list the vertexes on the cycle, as the edges are induced.
The prefermax cycle, , is such that and if then where is the maximal letter such that .
For example, if we set and , we have: .
Martin Mar34 proved that the cycle given in Definition 2 is Hamiltonian, i.e., that for steps there is always a such that , so is well defined, as demonstrated with Example 2.
The Hamiltonian cycle , given in Definition 2, corresponds to the well known prefermax De Bruijn sequence (defined, e.g., in Gol81 ). One challenge raised in the literature (see, e.g., SAWADA2017524 ) for such sequences is finding an efficiently computable function that maps each vertex on the cycle to its follower, called a shiftrule. We will arrive to such a rule at the end of the paper.
3 Two properties of the prefermax cycle
We first state and prove two properties of the prefermax cycle. These properties will be used later to prove properties of the game that we are going to propose and for its analysis in the following sections.
For the following propositions, let be the order induced by the sequence given in Definition 2, i.e., if where is as given in Definition 2. This is a linear order over because the sequence represents a Hamiltonian cycle of the De Bruijn graph.
Proposition 1.
For any such that , if then .
Proof.
By induction on the length of . If is empty, the statement is true from the definition of the prefermax cycle (Definition 2). For the induction step, assume that the statement is true for all of some constant length . We need to show that for any and any of length . Since and because the predecessor on the cycle of each of these vertices is a node in we have that at least vertices in this set precede . The term ‘predecessor’ is well defined here because . It assures us that is not the first vertex on the cycle. By the induction hypothesis, we have that , for any . Therefore, there are at least vertices in before . Since the follower of each of these vertices is in and because , we get that must be before . ∎
Consider again the sequence given in Example 2. If we take, for example, and , we see . If we take, as another example and , we see that . More generally we see that for any and whose combine length is two. Note that the proposition does not say where does fit, it may come before , after , or between the two.
Proposition 2.
Considering from Definition 2. For each , exactly one of the following is true for some and :

and ;

and ;

and .
Proof.
Let be a word of length over . From Proposition 1, the subsequence appears on the cycle in a decreasing order. By Definition 2, the subsequence also appears in a decreasing order. Since the predecessor of each node in the second list is either or a node from the first list, we get that if then the follower of must be and that if then the follower of must be . See an illustration of the proof in Figure 1. ∎
Consider the sequence given in Example 2 again. If we take, for example, , we see that the predecessor of is , the predecessor of is , and the predecessor of is . We see that, in this case, the leftmost digit of the predecessor is either zero or an increase by one of the rightmost digit of its successor. In this case, the node comes before the beginning of the first list considered in the proof, corresponding to having in Figure 1.
4 A combinatorial game
Our next step is a proposal of a combinatorial game that will, after some analysis, be used to derive an efficient computation of the predecessor in the prefermax sequence. In light of Proposition 2 we ask ourselves: Given , when do we need to increase, keep as is, or take a zero instead of when computing the predecessor of . We propose an indirect answer: A combinatorial game whose rules correspond to these options. One player, called Bob, can force an increase step while the other player, called Alice, can force a zero step when Bob does not want to increase. Alice’s goal is to continue as far as possible without repeating a state and Bob’s goal is to get to a repeated state as fast as he can. As we will prove later, the game is constructed such that best option for both player is to step along the sequence, i.e., that the optimal strategies for both players are equivalent to computing the predecessors of from Definition 2.
The following definition states the rules and the objectives of the game:
The shiftgame is a twoplayer combinatorial game played by Alice and Bob as follows: A play of the game consists of a sequence such that and if then:
where , are functions, called strategies for Bob and for Alice, respectively, such that for all . The game ends at state if and . Alice wins if and . Bob wins if . If and its a tie.
Note that this definition introduces the notion of strategies for the players. I,e,. that a function is a strategy for Bob if for all and it is a strategy for Alice if for all . For future use, we note the following observation: If is a strategy for Alice or for Bob and for all , then is also a strategy for the same player.
A play of the shiftgame can be such that . In this example, Bob plays on moves , i.e., , Alice plays on , i.e., , and neither play on . In this example, Alice won because the play reached in moves, which is less than moves.
This is a deterministic game with perfect information but it is not impartial (i.e., it is a partisan game), as there are differences, beyond who goes first, between Alice’s and Bob’s goals and moves. See Figure 2 for an illustration of how a round of the game is executed.
The shiftgame proposed in Definition 4 is a generalization of a game proposed in weiss2007combinatorial for solving a problem in controltheory. There, the game was only for the binary case () in which case the prefermax sequence is also called ‘preferone’. In terms of Definition 4, the binary game was
It is easy to verify that it is equivalent to the shiftgame. Indeed, the game proposed in weiss2007combinatorial and the strategies proposed there to solve it can generate a known shiftrule for the preferone sequence as shown in sawada2016surprisingly and in fredricksen1972generation .
Before we move to solving the
shiftgame, we state and prove a complexity property for it. There has been several criteria in the literature for classifying complexities of De Bruijn sequences, e.g.,
(chan1982complexities, ). One such criterion, for binary sequences, is the number of ones in the truth table of the feedback function that generates the sequence. For De Bruijn sequences generated by combinatorial games, this can be translated, e.g., to counting the number of moves that Bob plays, i.e., the number of ones in the truth table of Bob’s strategy. A result that goes along these lines is given in the next proposition:Proposition 3.
For every play, , of the shift game, let be the number of times Bob plays and be the number of times Alice plays. Then, .
Proof.
Let . From Definition 4, we get that and that if then
Since , then , and because for all , then . So and the required result follows from this inequality. ∎
If we look back at Example 4, we can count and see that and and verify that .
Next, we turn to establishing a connection between the prefermax and the shiftgame. We will first define a pair of strategies and such that if both Alice and Bob use the respective strategy, the play of the game follows the prefermax sequence (in reverse). Then, we will show that and are the unique strategies for each of the players, respectively, that guarantee not losing the game. This will give us that the efficient implementations of nonlosing strategies for both of the players, that we will provide in Section 5, can serve as an efficient shiftrule for the sequence.
The strategies and use the prefermax sequence as an internal ‘oracle’, as specified in the following definition:
Considering from Definition 2, let be the strategies for Alice and Bob, respectively, defined by
and
From Definition 2, we can see that is a strategy, i.e., for all , and the next proposition will show that is also a strategy, i.e., for all . The next proposition also shows that the computation of can be reduced to a computation of over a slightly alternated input. We will use this fact to simplify the analysis and to allow a succinct implementation of the strategies.
Proposition 4.
For every , and, for every , .
Proof.
For example, for and , if both players play according to the strategies above, then the resulting play is which yields a tie. We can see that in the example above, the play is exactly the prefermax cycle in reverse. The following proposition establishes that this is true for all and :
Proposition 5.
Let be the play of the shiftgame when Alice uses the strategy and Bob uses the strategy. Then, where is the prefermax sequence given in Definition 2.
Proof.
From Proposition 5 we have that if Alice plays according to and if Bob plays according to the game ends with a tie. In the next two propositions, we show that each of them wins against any other strategy. Then, in the two propositions that follow, we show that these strategies are the unique strategies with these properties.
Proposition 6.
If Bob applies the strategy he wins against any strategy that Alice may apply which is not and achieves a tie against .
Proof.
First, From Proposition 5 we know that if the players play by the strategies and respectively we get a tie. Now, Assume towards contradiction that there exists a strategy for Alice which wins against . Then, there must be a state where such that , and because otherwise the play is equal to the play with and which is, as said, a tie. Let be the first such state. By Proposition 2 and the Definition 4 of , we have that if then , and if then . If then and . If then and . In both cases and which is in contradiction with the assumption that is a winning strategy. ∎
Proposition 7.
If Alice applies the strategy she wins against any strategy that Bob may apply which is not and achieves a tie against .
Proof.
Assume towards contradiction that there exists a strategy for Bob which wins against and let be the play of the game with these two strategies. Consider the function such that for all in the order specified in Definition 2. By the definition of and of (Definition 4), if we have that . Otherwise, If and we have that thus and , so, by Proposition 2, we have that which gives us that . If and we have to check two cases:

If then , and so, by Proposition 2, we have that which gives us that .

If then and so, by Proposition 2, we have that which gives us that .
Thus, by this enumeration of all the three cases, we see that is a strictly decreasing along the play . Since the minimum of is attained at , we get that in contradiction to the assumption that Bob wins. ∎
The following two propositions establish the uniqueness of both and . Since it is easy to generate the prefermax sequence from an implementation of these strategies, these results establish a polynomial reduction from computing an efficient shiftrule for the prefermax sequence to efficient computation of nonlosing strategies for both players, a problem that we will solve in the next section.
Proposition 8.
is the only nonlosing strategy for Bob.
Proof.
Assume towards contradiction that there exists a nonlosing strategy for Bob such that . Let be the play of the game where Bob applies and Alice applies . Let be as in Proposition 7. For , assuming that , we have two options:

If and we have, by the definition of , that . By the definition of then . By the definition of the game, we have that . By Proposition 2, , i.e., .

If and we have two cases:
We get that is strictly decreasing along the play . In particular, which means that . Since is assumed to be a nonlosing strategy for Bob, therefore, by the definition of the ending condition of the game, we must have .
Since , there must be a such that . Therefore, the length of the game, , must be smaller than . By the definition of the game, Bob loses, in contradiction to the assumption that is a nonlosing strategy for Bob. ∎
Proposition 9.
is the only nonlosing strategy for Alice.
Proof.
Assume towards contradiction that there exists a nonlosing strategy for Alice such that . Let be the play of game when Alice and Bob use the strategies and , respectively. Let be the first index in this play such that . Let and be such that . Note that , as either or but not both.
By Proposition 5, since until Alice and Bob applied the strategies and , respectively, we have that , i.e., the game follows the reversed prefermax sequence until .
We first show that must be zero. Otherwise, assume towards contradiction that . By the definition of , . By Proposition 1, since , then , i.e., . Consider, now, the strategy such that for all and . By Observation 4 is a strategy. Let be such that if and if (exactly one of them must be true because ). By Observation 4 is a strategy. When Bob applies and Alice applies , we have that the play follows the reversed prefermax sequence until it gets to and then, by the definition of the game, since , it goes to which is a state that was visited before, i.e., Bob wins. This contradicts the assumption that is a nonlosing strategy or the fact (Proposition 7) that is a nonlosing strategy. Thus .
If then, by the definition of , which, by Proposition 2, means that or . But, since , we have that so, by the definition of the game, since , we have which is a state that we already visited, i.e., Bob wins. This is in contradiction to the assumption that is a nonlosing strategy for Alice.
If then, by the definition of and of , which, by Proposition 2, means that or . But, since , we have that so, by the definition of the game, since , we have which is a state that we already visited, i.e., Bob wins. This is in contradiction to the assumption that is a nonlosing strategy for Alice. ∎
5 An efficient computation of the nonlosing strategies for both players
In this section we propose algorithms for efficient computation of the strategies for both players in the shiftgame. As said before, this can also be translated to an efficiently computable shift rule for the prefer max sequence. The main ingredient in this is the function given in the following definition together with two helper functions, and , that we will later use in the algorithms and in their analysis:
For a state and , let:

be the value of read from position .

be the (maximal) value of .

be the head of .

be the tail of .
The function given in Definition 5 transforms a state to a number by reading its symbols as a number in base from the th place to the left in a cyclic order. The function gives the index of the place from which reading the value is maximal. The function gives this maximal value, i.e., . The function gives the index of the least significant nonzero digit of as reads it.
For example, , , and , so and thus and .
As the function plays a key role in the algorithm for computing the strategies that we propose in the sequel and, consequently, also in the shiftrule for the prefermax sequence, we state its computational complexity as follows:
Proposition 10.
The function can be computed in time and memory.
Proof.
We can compute each iteration of the based on the in time and memory using the equation where . Computing is and checking which value is the maximal is also since we only need to check if it is greater then the previous maximum, where the first maximum is . Also, from Definition 5, we can can compute from in memory and time. ∎
We turn now to the analysis of the behavior of the function over plays of the shiftgame. The following three claims establish bounds on the difference where and are consecutive states in a play of the game. If then, by definition, is either , , or . Since in the third case , we only need to analyze the first two cases.
Claim 11.
.
Proof.
If and then:
∎
Claim 12.
If and , then .
Proof.
Let . Since , we can write and for some and some . Let . From Definition 5, Since the symbol at the head cannot be zero, we have that . Assume towards contradiction that . Then which contradicts that is the head. Thus . ∎
Claim 13.
If and , then .
Proof.
If , , , and then:
∎
The above three propositions give us the tools needed for describing a nonlosing strategy for Alice and Bob, as follows. The ‘trick’ for Alice is to force Bob to have at least once every steps of the game if he does not want to lose in these steps. Then, by Claim 11 and Claim 13, we get that increases more than it may decrease between any two states in which we increase the value, which means that Alice guarantees that the play reaches the state with the maximal value of , which is , from which Alice can easily win in moves.
Let be the strategy for Alice defined by
and let be the strategy for Bob defined by
From Definition 5, we can see that and are strategies, i.e., , since .
Our next goal is to prove that is a nonlosing strategy for Alice. To this end, we define a variant of the game and establish three claims, as follows.
The infinite shiftgame goes exactly as the game in Definition 4 the only difference being that a play does not end when , just when . In this game, Bob wins when the play goes forever, Alice wins if and there is no option for a tie.
Claim 14.
In any play of the infinite shiftgame where Alice applies the strategy and Bob applies a strategy
Comments
There are no comments yet.