The Sprague-Grundy function for some nearly disjunctive sums of Nim and Silver Dollar games
Graham Farr, Nhan Bao Ho

TL;DR
This paper extends classical impartial games Nim and Silver Dollar by introducing a new interaction operation, analyzing its Sprague-Grundy function, and providing algorithms and periodicity results for the modified game structures.
Contribution
It introduces a new game operation combining subpositions with limited interaction, and analyzes the resulting Sprague-Grundy functions with algorithms and periodicity proofs.
Findings
Simplified computation of Sprague-Grundy functions for certain combined games.
Development of an algorithm for two-token Star Nim with specific Sprague-Grundy values.
Proving the eventual additive periodicity of the difference sequences in these games.
Abstract
We introduce and analyse an extension of the disjunctive sum operation on some classical impartial games. Whereas the disjunctive sum describes positions formed from independent subpositions, our operation combines positions that are not completely independent but interact only in a very restricted way. We extend the games Nim and Silver Dollar, played by moving counters along one-dimensional strips of cells, by joining several strips at their initial cell. We prove that, in certain cases, computing the Sprague-Grundy function can be simplified to that of a simpler game with at most two tokens in each strip. We give an algorithm that, for each Sprague-Grundy value g, computes the positions of two-token Star Nim whose Sprague-Grundy values are g. We establish that the sequence of differences of entries of these positions is ultimately additively periodic.
| 10 | 0 | 2 | 3 | 6 | 21 | 20 | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 9 | 0 | 1 | 5 | 19 | 20 | 18 | 21 | ||||||||
| 8 | 0 | 2 | 5 | 4 | 18 | 17 | 20 | 19 | |||||||
| 7 | 0 | 1 | 3 | 4 | 14 | 17 | 18 | 19 | 11 | ||||||
| 6 | 0 | 2 | 3 | 4 | 13 | 12 | 16 | 10 | 11 | 18 | |||||
| 5 | 0 | 1 | 9 | 10 | 11 | 8 | 7 | 15 | 16 | 17 | 13 | ||||
| 4 | 0 | 2 | 9 | 10 | 11 | 6 | 7 | 8 | 14 | 15 | 16 | 12 | |||
| 3 | 0 | 1 | 6 | 8 | 5 | 9 | 7 | 12 | 13 | 10 | 11 | 15 | 17 | ||
| 2 | 0 | 4 | 5 | 3 | 7 | 8 | 6 | 10 | 11 | 9 | 13 | 14 | 12 | 16 | |
| 1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| a/b | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsArtificial Intelligence in Games · Digital Games and Media
The Sprague-Grundy function for some nearly disjunctive sums of Nim and Silver Dollar games
Graham Farr
Faculty of IT, Monash University, Clayton, Victoria 3800, Australia
and
Nhan Bao Ho
Department of Mathematics and Statistics, La Trobe University, Bundoora, Victoria 3086, Australia, Australia
[email protected], [email protected]
Abstract.
We introduce and analyse an extension of the disjunctive sum operation on some classical impartial games. Whereas the disjunctive sum describes positions formed from independent subpositions, our operation combines positions that are not completely independent but interact only in a very restricted way. We extend the games Nim and Silver Dollar, played by moving counters along one-dimensional strips of cells, by joining several strips at their initial cell. We prove that, in certain cases, computing the Sprague-Grundy function can be simplified to that of a simpler game with at most two tokens in each strip. We give an algorithm that, for each Sprague-Grundy value , computes the positions of two-token Star Nim whose Sprague-Grundy values are . We establish that the sequence of differences of entries of these positions is ultimately additively periodic.
Key words and phrases:
combinatorial games, disjunctive sum, Sprague-Grundy function, Nim, Star Nim, Silver Dollar, Star Silver Dollar, ultimately periodic.
2000 Mathematics Subject Classification:
91A46
Nhan Bao Ho was a 2014 Endeavour Research Fellowship recipient. He also thanks Monash University for hosting the fellowship.
1. Introduction
In the theory of combinatorial games, the disjunctive sum plays a central role. This dates back to Bouton’s pioneering work on Nim, which became the archetypal impartial game [4]. A disjunctive sum represents a game that can be broken down into independent smaller games. Such a game can be efficiently analysed in a divide-and-conquer fashion; specifically, its Sprague-Grundy value may be obtained from the Sprague-Grundy values of its component games using Nim-addition (i.e., bitwise mod-2 addition). We briefly review the basics of combinatorial game theory in Section 1.1.
In many games, disjunctive sums arise commonly in actual play: a position that was initially large and complex may develop into a set of totally separate self-contained sub-positions. Indeed, analysis of this phenomenon in the partizan game Go was the initial spark that led Berlekamp, Conway and Guy to develop the theory of surreal numbers and combinatorial games [6, Prologue]. But it is probably even more common, in practice, for a game position to develop sub-positions that are mostly, but not entirely, self-contained, so that there is still some small amount of interaction between them.
It is natural, then, to investigate impartial games obtained by combining smaller games that are “nearly” independent, but not completely so. This line of enquiry has analogies in many areas of mathematics, for example in connectivity in graphs, where small separating sets of vertices or edges in connected graphs enable efficient divide-and-conquer steps in many algorithms.
In this paper, we study one of the simplest possible ways of combining impartial games in a “nearly independent” way. We focus on a family of games that generalize Nim. These are based on moving tokens along one-dimensional strips of squares, where squares are numbered by nonnegative integers. A single Nim-heap is represented by a single strip with a single token. The index of the token represents the size of the heap. The token may be moved to any lower-numbered square. A general Nim position is obtained by taking a disjunctive sum of Nim-heaps, in which all the strips are disjoint.
We introduce Star Nim, in which we take some number of strips and identify the 0-squares of each strip. We can picture the strips radiating out from their shared square at position 0. The token on each strip may be in any position, including 0, but we forbid a square from containing more than one token. So, as soon as a token is moved down some strip to the 0-square, all the other tokens on the other strips are forever prevented from going there. We also look at Star versions of the Silver Dollar game.
1.1. The Sprague-Grundy theory for the impartial games
In a two-player combinatorial game, the players move alternately, following some set of rules for moves. There is no hidden information and no element of luck. All games discussed in this paper are short and impartial. A short game has a finite number of positions and each position can be visited once (no loop) and so the game terminates after a finite number of moves. A game is impartial if the two players have the same options for moves from every position. The player who makes the last move wins (normal convention). More comprehensive theory can be found in [2, 6].
A position is an -position if the next player (the player about to move) can have a plan of moves to win and a -position otherwise [2]. The terminal position is the position without a legal move, and so is a -position.
Introduced by Grundy [13] and Sprague [15, 16], the Sprague-Grundy value of a position is defined recursively as follows: the terminal position has value [math], and if for every such that , one can move from to some such that and there is no move from to such that . Note that a position is a -position if and only if its Sprague-Grundy value is zero. The following lemma follows from the definition of Sprague-Grundy values.
Lemma 1**.**
[8]** For each , the set of positions whose Sprague-Grundy value is satisfies the following conditions:
- (1)
there is no move between two distinct positions in , and 2. (2)
from any position not in , there exists a move that terminates in .
The Sprague-Grundy function plays an important role in the study of the disjunctive sum of games defined as follows. Given two games and , the two players alternately move, choosing either of the two games and moving in that game. The play ends when there is no move available from either of the games. In this paper, a sum means disjunctive sum. The following theorem give us a winning strategy for playing sums, and uses bitwise mod-2 addition, denoted by , of binary representations of numbers.
Theorem 1** ([13, 15, 16]).**
The Sprague-Grundy value of the sum of two games and is the Nim-sum .
The game of Nim, analyzed by Bouton [4], provides a typical example of sums. This game is played with a finite number of piles of tokens. A move consists of choosing one pile and removing an arbitrary number of tokens from that pile. A game with piles is denoted by Nim. Nim is a sum of multiple one-pile Nim. The Sprague-Grundy function of Nim is the Nim-sum of the sizes of the single piles. The following lemma follows from Theorem 1.
Lemma 2**.**
[4]** The Sprague-Grundy value of Nim is .
1.2. Star Silver Dollar
The game of Silver Dollar [6] is played with a finite strip of squares labeled from the left end by with at most one token on each square. The two players alternately move, choosing one token and moving it to an empty square that is labeled with a smaller number without jumping over any of the other tokens. The game ends when there is no move available and the player who makes the last move wins.
For example, in Figure 1, the allowed moves are: move the token on square 2 to square 1 or 0; or move 5 to 4 or 3; or move 8 to 7; or move 10 to 9. In this position, the token on square 6 cannot move.
An analysis of Sprague-Grundy values for Silver Dollar will be given in section 1.3.
We generalize the game of Silver Dollar to multiple strips. Given Silver Dollars, we overlap the zero squares of these games, as illustrated in Figure 2. A move consists of choosing an arbitrary token and moving it to some smaller empty square on the same strip without jumping over any token. The next player to move can choose a different strip. We call this game Star Silver Dollar.
Remark 1**.**
We can assume that our Star Silver Dollar does not have a token on square 0. If there is token on this square, the game is the disjunctive sum of separate Silver Dollars and it can be solved as shown in Remark 2. ∎
We use to represent a Silver Dollar with tokens in the squares with . For example, the position in Figure 1 is represented by . The Star Silver Dollar formed by two Silver Dollars is represented by and so on. We use -Star Silver Dollar when emphasizing that the game has strips.
Star Silver Dollar is called Star Nim if each strip has only one token. The game -Star Nim is Star Nim with strips.
Several games played on strips have been studied, including Hexad [5], Welter [17, 18] and its variants [9, 12]. One may be interested in studying the combination of these games using the idea of Star Silver Dollar.
We next recall the Sprague-Grundy function for Silver Dollar for the reader’s convenience.
1.3. An analysis of Silver Dollar
The Spague-Grundy function for Silver Dollar is analyzed in [6, Chapter 11] as follows. For each Silver Dollar position ,
[TABLE]
For example, the Spague-Grundy value for the Silver Dollar position is . Note that is the number of empty squares between the two squares and .
Note that Silver Dollar can be considered as the game of Nim in which each term in the formula for Sprague-Grundy function above is a pile in Nim. The only difference with Nim is that Silver Dollar sometimes increases one pile when reducing another pile. This is because moving a token reduces the gap between that token and token on its left but increases the gap between and the token on its right. However, this increase does not repeat forever and also does not affect the winning strategy.
Remark 2**.**
It can be seen that Star Silver Dollar with token in square 0 is the sum of separate Silver Dollar and so it is solved by using the Nim-sum of Sprague-Grundy values and the analysis of Silver Dollar given just above. ∎
For example, the Star Silver Dollar in Figure 3 is exactly the sum of three separate Silver Dollar: , , and .
The outline of paper is as follows. In the next section, we show that the Sprague-Grundy function for Star Silver Dollar can be simplified to that for a simpler one where each strip has at most two tokens. In Section 3, we characterize the -positions for -Star Nim with . In Section 4 we analyze the Sprague-Grundy function of 2-Star Nim. We give an algorithm that produces positions whose Sprague-Grundy values are . We prove a periodicity property of the sequence of positions whose Sprague-Grundy values are . We then prove an additive periodicity property of the Sprague-Grundy function. In Section 5, we discuss some research direction for further study. We also include some code written on Maple in Appendix A for the reader’s convenience.
2. The Sprague-Grundy function for Star Silver Dollar
We show that Star Silver Dollar can be described as a disjunctive sum of a simpler Star Silver Dollar with at most two tokens on each strip and separable Silver Dollars (Theorem 2). We then examine the cases for the simplified Star Silver Dollar. When each strip has an odd number of tokens, this simplified game is derived from Star Nim (Corollary 1). When each strip has an even number of tokens, we establish a formula for the Sprague-Grundy function (Corollary 2).
Definition 1**.**
Given Silver Dollars with , for each , let be the Silver Dollar containing exactly the smallest token (resp. the two smallest tokens) of if has an odd (resp. even) number of tokens, and be the Silver Dollar containing the remaining tokens of . ∎
In other words, if then and if is odd and and otherwise. Here stands for Head and stands for Tail. Note that is not empty in the even case ( is even).
Example 1**.**
We give an example corresponding to the case where has an odd (resp. even) number of tokens in Figure 4 (resp. Figure 5).
Theorem 2**.**
The game of Star Silver Dollar is exactly the disjunctive sum of new Star Silver Dollar and new Silver Dollars . In other words,
[TABLE]
Remark 3**.**
Note that Nim-sum can be computed in linear time and so each can be computed in polynomial time using the Sprague-Grundy function for Silver Dollar (Section 1.3). Therefore, the two functions and are polynomial-time computable. ∎
Example 2**.**
Consider Star Silver Dollar . We have , , , , . Then
[TABLE]
Proof of Theorem 2.
For each Star Silver Dollar position , set
[TABLE]
We need to verify two facts:
- (1)
if there exists a move from to , and 2. (2)
for any , there exists a move from to such that .
It then follows that .
(1) Suppose one moves from to some by moving a token in some . Without loss of generality, we can assume that . Denote by the new Silver Dollar obtained from by this move. Then, and
[TABLE]
in which either and the move is available in or and the move is available in . In both cases, and so since is a constant.
Note that this argument also holds for the case when the zero square in the position is occupied. In fact, in this case, the game is the disjunctive sum of separate Silver Dollars and the move from to is exactly a move in a single Silver Dollar which changes the value of that game while keeping the values of other Silver Dollars unchanged.
(2) Let . Recall that each is a Silver Dollar with an even number of tokens . The solution for Silver Dollar gives . Expanding all gives
[TABLE]
By SG theory of sums, the right-hand side is the Sprague-Grundy function of the sum of Star Silver Dollar game and multiple one-pile Nim. Denote this sum by . Then .
By the definition of , there exists one move from to some such that . There are two possibilities for this move: either (i) moving some token in or (ii) reducing some Nim.
In the former case (i), without loss of generality, we can assume that this move affects some token in , resulting in . Then
[TABLE]
Note that this move does not affect any Nim. Consider the position obtained from by this move in . Note that this move does not affect any . We have
[TABLE]
Substituting the expansion of into the right-hand side gives .
In the latter case (ii), assume that tokens have been removed from some Nim. Without loss of generality, assume that . Then
[TABLE]
Consider the position obtained from by moving the token in the square to the square in , resulting in . This move is available since and so . Moreover, this move does not affect . By the definition of , we have
[TABLE]
Substituting the expansions of and into the right-hand side gives . ∎
We consider the two special cases of Theorem 2 in which all strips have the same parity of numbers of tokens. The following is immediate from Theorem 2.
Corollary 1**.**
*If all strips have odd numbers of tokens, the game of Star Silver Dollar is the sum of one Star Nim, with the lowest position token on each strip and separate strips with the remaining tokens. *
For example, direct calculation shows that and so we have
[TABLE]
Corollary 2**.**
If all strips have even numbers of tokens, the game Star Silver Dollar is exactly the sum of its strips. In other words, if for then
[TABLE]
For example,
[TABLE]
Proof of Corollary 2.
By Theorem 2, it remains to prove that
[TABLE]
if every has exactly two tokens. The argument is exactly similar to the solution of Silver Dollar with even tokens. ∎
3. -positions of Star Nim
beginning simple cases, the two games are by far different, from winning strategy to Sprague-Grundy functions.
We characterize the -positions of -Star Nim for . Except for the two positions and , 2-Star Nim and 2-pile Nim have the same -positions. if the payer who makes the last move loses).
Proposition 1**.**
The 2-Star Nim is a -position if and only if either or .
Note that the condition in Proposition 1 is equivalent to , which is similar to -positions in Nim.
The -positions of 3-Star Nim coincide with those of 3-pile Nim.
Proposition 2**.**
The 3-Star Nim position is a -position if and only if .
Proof.
Set . We need to verify the following two facts:
- (1)
there is no move between two distinct positions in ; and 2. (2)
from any position not in , there exists a move that terminates in .
For (1), let . Then . For every , moving from to in the first strip results in position as . Similarly, moving in the second or third strip also results in positions not in .
For (2), let . Then . As shown by Bouton [4], one can find a such that and , or and , or and . If the first (resp. second, third) case holds, moving from (resp. , ) to in the first (resp. second, third) strip terminates in . ∎
It appears complicated to generalise the above results to 4-Star Nim. We obtain a formula for -positions with only as follows.
Proposition 3**.**
The 4-Star Nim position with is a -position if and only if .
Proof.
Note that the 4-Star Nim position is exactly the 3-pile Nim position and so it is a -position if and only if . Set
,
,
.
We need to verify the following two facts:
- (1)
there is no move between two distinct positions in ; and 2. (2)
from any position with , there exists a move that terminates in .
For (1), it can be verified that there is no move between positions in and between positions in , using property if . We show that there is no move from a position in to a position in . Let . Then .
If we move from to in the first strip, the obtained position is . Note that and cannot hold at the same time. To see this, consider the binary representations of the numbers and . If , an even number of end in 1, so an odd number of end in 1, so .
If we move from to in the second strip, the obtained position is (after swapping the first two strips). Assume by way of contradiction that this position belongs to . Then so that . This contradicts with . If and we move from to in the second strip, the obtained position is . Assume by way of contradiction that this position belongs to . Then , contradicting with .
Similarly, one can check that a move from in the third strip or from in the fourth strip cannot lead to either or .
For (2), let with . If , since . Consider the Nim position . As shown by Bouton [4], there exists such that (1) and or (2) and or (3) and . Without loss of generality, we can assume that the case (1) holds. Consider the move from to in the second strip. One can check that the obtained position belongs to .
If , since . Consider the Nim position . As shown by Bouton [4], there exists such that (1) and or (2) and or (3) and . Without loss of generality, we can assume that the case (1) holds. If , . The obtained position can be represented as 4-Star Nim position . If , the obtained position is . ∎
Direct calculation shows that many -positions of Star Nim also satisfy the condition for -positions in Nim. For example, there are 5089 -positions with in Nim of which 4593 are -positions in Star Nim. There are 112 -positions with of which 79 are -positions in Star Nim.
4. Sprague-Grundy function of 2-Star Nim
In the rest of paper, we study 2-Star Nim. For convenience, we omit square bracket in position format. A position will be denoted by .
Table 1 provides the Sprague-Grundy values of -Star Nim for , . We establish several properties of the extension of this table.
We characterize 2-Star Nim positions whose Sprague-Grundy values are at most 5. Given some Sprague-Grundy value , we give an algorithm that computes the sequence \big{(}(a_{i},b_{i})\big{)}_{i\geq 0} of 2-Star Nim positions whose Sprague-Grundy values are . We show that the sequence is ultimately periodic. Finally, we prove the ultimately additive periodicity of rows (and similarly columns) of the matrix of Sprague-Grundy values and conjecture the ultimate periodicity of diagonals parallel to the main diagonal.
4.1. -Star Nim positions of small Sprague-Grundy values
We are able to characterize positions of -Star Nim whose Sprague-Grundy values are up to as follows.
Proposition 4**.**
Denote by the set of positions whose Sprague-Grundy value is . We have
- (i)
; 2. (ii)
; 3. (iii)
; 4. (iv)
; 5. (v)
; 6. (vi)
;
Proof.
Recall that is part of Proposition 1. For each with , one needs to verify two facts: (1) there is no move between two positions in , and (2) from any position not in , there exists one move to some position in . The verification of the claims is simple and we leave to the reader. ∎
4.2. An algorithm for the Sprague-Grundy function for 2-Star Nim
Denote by the sequence \big{(}(a^{g}_{0},b^{g}_{0}),(a^{g}_{1},b^{g}_{1}),(a^{g}_{2},b^{g}_{2}),\ldots\big{)} with , called the -sequence, of positions whose Sprague-Grundy values are such that if . Note that the set in Proposition 4 is exactly the set of elements in the sequence . We establish an algorithm that computes the sequence member from various for . We assume as the case for has been solved linearly in Proposition 1.
-sequence for all and the first members for . We introduce an algorithm that computes sequence member .
We denote the sequence computed by the algorithm by T^{g}=\big{(}(x^{g}_{n},y^{g}_{n})\big{)}_{n\geq 0}, and will shortly show that the sequences and are the same.
Algorithm 1**.**
Input: .
Previously computed: for ; for and all such that .
- (1)
. 2. (2)
, where is the smallest nonnegative integer such that
- (a)
, and 2. (b)
for .
Output: . ∎
Remark 4**.**
The algorithm has the same overall structure as the Wythoff-Sprague-Grundy (WSG) algorithm due to Blass and Fraenkel [3], for the game Wythoff, although there are many differences in the details of analysis. ∎
Later, Example 3 shows the calculation of together with the data required, and is illustrated in Figure 6. We now discuss Algorithm 1.
Remark 5**.**
- (1)
By the definition of , Step (1) of Algorithm 1 implies that if then . 2. (2)
To compute the term of sequence , we need the terms of each of the sequences (for ) up to a point where we can check if . Note that for all and with at most values . Therefore, . Thus, we assume esch has been constructed up to the position whose first entry is equal or greater than . 3. (3)
We have . In fact, since , we have . Also in Step (1), the set has at most elements while the set has elements. Therefore, . Thus, . 4. (4)
We have . In fact, there are at most values that can not be assigned to. In each , the worst case is when contains pairs, as mentioned in (2). The second entries of these pairs can not be assigned to . For , there are such values. Thus, . By (3), we also have . ∎
Remark 6**.**
We analyse the complexity of Algorithm 1. Step (1) first sorts the set in increasing order, requiring O\big{(}n(\log n+\log g)\big{)} steps using Radix Sort, since we have integers of O bits each. It then scans the list of up to elements to find its , requiring O comparisons of these integers. Thus, Step (1) takes O\big{(}n(\log n+\log g)\big{)} steps. The construction of each by Algorithm 1 up to a point as mentioned in Remark 5 requires up to pairs in the worst case. We have proved in Remark 5 that . We compare with only the first entries of these pairs, each requiring time O until we find one entry equal to or greater than . This process requires O steps. If this condition is meet, we compare with the second entry, requiring time O. Thus, assuming we have previously computed the required terms of for , Step (2) costs O steps. The total time complexity of Algorithm 1 is therefore O\big{(}n(\log n+\log g+g\log n)\big{)}. This is exponential in the sizes of the inputs and . ∎
Algorithm 1 could be used as part of an iterative scheme to compute the in turn, provided the computation is organised so that the required previously computed pairs are always available.
Theorem 3**.**
The sequence computed by Algorithm 1 coincides with the -sequence .
Proof.
We first verify the termination of the algorithm. Step (1) requires at most comparisons. For each in Step (2), needs to be compared with no more than values of and needs to be compared with no more than positions of with and . We can ignore all other with since by Remark 5. Now . Therefore, the algorithm must terminate.
We prove by induction on that the sequence computed by Algorithm 1 coincides with the -sequence . We need to verify the following conditions:
(i) ;
(ii) there is no move between two positions in ;
(iii) from every position not in , there exists one move that terminates in .
The condition (i) holds since in the step (2) of the algorithm, is chosen such that it has not appeared in any sequence for .
For (ii), note that if and belong to then by Step (1) and by Step (2). Thus, (ii) holds.
For (iii), let with . We show that there is a move from to some position in . Step (1) implies that the set contains all nonnegative integers. It follows that there exists some index such that either or .
If the latter case holds, we have since and . One can move the token in the square to the square , terminating in .
If the former case holds, we compare with . Note that . If , one can move the token in the square to the square , terminating in . We now consider the case .
We claim that . Since , if then Step (2) must choose , giving a contradiction.
Thus, there exists such that and . Also note that implies by Remark 5. Thus, moving the token from the square to the square results in the position . ∎
Example 3**.**
We illustrate data required to run Algorithm 1 in Figure 6. To calculate , step (1) gives . In step (2), we start with , giving satisfying (2a). But appears in so step (2b) fails. By increasing to we have appearing in , so step (2b) fails. Then we increase to , giving and satisfying step (2). Therefore, . ∎
We now improve Algorithm 1. Note that to compute in the sequence , Algorithm 1 computes a set whose size is . We will show that there are several ways we can improve Algorithm 1. In step (1), we can replace the existing set by a set of size at most . In step (2a), we can replace the existing set by a set of size at most . In step (2b), instead of scanning all pairs in , we only need to scan one pair. Thus, the algorithm needs to scan only O values.
Lemma 3**.**
, , , and for
[TABLE]
Proof.
The lemma can be proved by induction on . ∎
We first prove lower and upper bounds for the Sprague-Grundy function.
Proposition 5**.**
For -Star Nim, we have for positive integers .
Proof.
We first show that . The claim can be proved by induction on . Note that the claim holds for by Lemma 3. The remaining argument is straightforward and we leave it to the reader.
holds for all for some . We show that the theorem holds for . Clearly the theorem holds for . Assume that the theorem holds for for some . We show that the theorem holds for , . We have that , as required. By the principle of induction, for all .
We next prove that . Assume by way of contradiction that for some and with . We can choose the smallest such integer . Moreover, corresponding to this , we can choose the smallest such integer . Assume that for some . Consider the position . Since is the smallest integer such that and , we have . Since one can move from to , and so . Therefore, there exists some position with such that one can move from to and . We have either and or and .
The former case cannot hold as and there exists a move from to (moving the token on the square to the square ). Therefore, the latter case holds. By the inductive hypothesis on , we have for all and so , giving a contradiction. ∎
We introduce two concepts that we will use to improve Algorithm 1 by reducing the amount of data used. In Step 1 of Algorithm 1, we can skip all values smaller than , then count from to find the smallest integer not in the set. Similarly, in step (2a), we can start comparing with those values not smaller than rather than all . This results in the following concept.
Definition 2**.**
Let be a finite set of nonnegative integers and let be a nonnegative integer. Set . ∎
For example, if then , .
In step (2b), there is at most one value equal to . We know the first entries in each are increasing. Suppose we have already scanned the first pairs in whose first entries are smaller than to compute . Then when computing , we can skip these scanned values. We would like to mark a position to record that we have already scanned up to there. The following concept helps us to do so.
Definition 3**.**
For each , there exists some in column such that . For convenience, denote by this index . The existence of is straightforward since by Remark 5. ∎
For example, one can check some first elements of for as follows:
[TABLE]
Let . Then (since , ), (since , ), and (since , ).
We now show that the sets scanned in Algorithm 1 can be replaced by new sets of smaller sizes.
Lemma 4**.**
The following properties hold for Algorithm 1:
- (1)
; 2. (2)
* is the smallest nonnegative integer such that*
- (a)
, and 2. (b)
.
Proof.
(1) By Remark 5, if and moreover if . Therefore,
[TABLE]
In the set on the right-hand side of the last equation, we can exclude all members smaller than . We now do this task.
- (i)
By Remark 5, for and so we can exclude these . 2. (ii)
For , by Remark 5, . Combining this and Proposition 5 gives . Thus, we can exclude all with . Finally, we exclude those for .
Therefore, (1) holds.
(2) By Remark 5, . For , it has been shown in (ii) above that and so . Therefore, in Step (2a) of Algorithm 1, if and only if .
For the condition (2b) in Algorithm 2, we need to compare with only . This is because for all . ∎
We have following bounds for .
Corollary 3**.**
For given , we have .
Proof.
Therefore, . Also in step 1, the set has at most elements while the set has elements. Therefore, . In Lemma 4, the set has at most values different to . Therefore, . reaches the minimum , giving the gap . ∎
We now improve Algorithm 1 so that we need only O values for input.
Definition 4**.**
For all . Set
,
,
,
. ∎
Algorithm 2**.**
Input: .
Previously computed: .
- (1)
. 2. (2)
, where is the smallest nonnegative integer such that
- (a)
, and 2. (b)
(x^{g}_{n},x^{g}_{n}+z)\neq\big{(}\min(T^{k}_{n}),\max(T^{k}_{n})\big{)} for . 3. (3)
.
Output: with . ∎
The next result follows from Lemma 4.
Lemma 5**.**
Algorithm 2 computes , and with .
Example 4**.**
We illustrate the data required to run Algorithm 2 in Figure 7. To calculate , the input, illustrated in given white box, includes , , , , , , , , .
Step (1) gives as the smallest integer bigger than and not in the set .
In step (2), we recursively calculate for . These new sets are in colored boxes in the first three columns. , , , , , . We can now ignore for . Let us take the opportunity to discuss the role of in Definition 3. Let , based on Definition 3, is the index such that to and . This gives or . Also in Figure 7, one can see that we have replaced the pair by and then and end with before assigning to and to . The same process is also applied for .
In step (2), we next start with , giving . But appears in . By increasing to we have appearing in . Then we increase to , giving and satisfying step (2). Therefore, .
In step (3), we assign and . ∎
Remark 7**.**
There are three improvements in Algorithm 2.
- (1)
the set has at most elements; 2. (2)
has to be compared with only values ( for ) rather than values as in Algorithm 1; 3. (3)
has to be compared with only pairs for rather than up to pairs with as in Algorithm 1 (Remark 5). ∎ pairs to be compared.
Remark 8**.**
Note that , and , and so Algorithm 2 stores only values in and \bigcup_{k=0}^{g-1}\big{(}T^{k}_{n}\cup Y^{k}_{n}\big{)}. By Remark 5 and Corollary 3, these values are all at most . We will use this finiteness to prove a periodicity property in the next section. ∎
4.3. A periodicity property of -sequences
We discuss the pattern of in the -sequence when increases. One can see in Proposition 4 that for , will eventually be a constant. When is large enough, this need not happen. Nonetheless, we will show that is eventually periodic. For example, for , the sequence is the repetition of “3, 3, 4, 3, 3, 4, 3, 3, 4, 4, 4, 4”.
Recall that a sequence is said to be ultimately periodic if there exist and such that for all .
We will modify Algorithm 2 to obtain a new algorithm computing . In the new algorithm, we will overcome the increasing values in so that we only need to store bounded values, making the algorithm able to be implemented on a finite state machine. This helps us to prove the periodicity of the difference . The following lemma gives bounds on the values used in Algorithm 2.
Lemma 6**.**
Algorithm 2 works with numbers at most and at least .
Proof.
In column , the first entries are increasing. For all , by Proposition 5, we have . In each column , we need to calculate up to the point (the first one from the bottom such that the first entry is greater than ) for the first entries and for the second entries. By Corollary 3, we have . For the second entries, by Proposition 5, we have . 3.
The smallest value used by the algorithm is . Recall that by Corollary 3. By Definition 3, we have . Also by Corollary 3, . Therefore, . ∎
Definition 5**.**
Algorithm 3 is obtained from Algorithm 2 as follows. Let , , , , . We replace by respectively. ∎
The following lemma is straightforward.
Lemma 7**.**
The output of Algorithm 3 is obtained by subtracting from every value in the output of Algorithm 2.
We prove the following.
Theorem 4**.**
For every -sequence , the sequence is ultimately periodic.
Proof.
By Remark 8, Algorithm 2 has used at most stored values. By Lemma 6, values used in Algorithm 2 are between and . Therefore, values used in Algorithm 3 are between [math] and . Here is the number of values in the integer interval . Hence, Algorithm 3 can be implemented on a finite state machine. The algorithm repeatedly returns values and so the sequence is ultimately periodic. ∎
4.4. The ultimately additive periodicity of Sprague-Grundy values
A sequence is said to be additively periodic if there exist and such that for all [1].
We show that in the expanded table of Table 1, every row (column) is ultimately additively periodic. For example, for , the sequence is ultimately additively periodic with the period , respectively. There is a remarkable pattern with these periods . The pattern is as follows:
[TABLE]
We do not yet know , so we do not know if this pattern continues.
Ultimately additive periodicity has been found for the Wythoff game and some of its variants [7, 10, 11, 14]. In these variants, the players alternately move from a position , following some given rules. For example, a move in Wythoff is one of following options: with ; with ; with . It has been proven for these variants that the sequence is ultimately additively periodic for every . Now we prove this periodicity for 2-Star Nim. The technique used here was introduced by Landman for Wythoff [14].
Theorem 5**.**
The sequence is ultimately additively periodic for every .
Proof.
Set and for . By Proposition 5, . Note that is ultimately additively periodic if and only if is ultimately periodic. We prove the latter by showing that can be computed on a finite state machine.
Set . By the definition of , . Note that the number of elements in increases along with the increase of . We first overcome this constraint.
Set . By Proposition 5, . Therefore, . Note that if and so we can exclude these Sprague-Grundy values in when computing . We can skip those and assume that . Set . Then .
Set
, ,
, . Then whose set has at most elements.
Thus, we have shown that can be computed from at most values regardless of how large is. The next step is to show that we can store only a finite number of bits to compute regardless of the increase of .
Define to be the string of bits such that the bit (with ) is if and [math] if otherwise. Intuitively, is obtained from the sequence by setting the bit to if and [math] if otherwise. Equivalently, is obtained from the string of bits by setting the bit to [math] if and if otherwise.
We next define as the string of bits such that the bit (with ) is if and [math] if otherwise. Similarly, is the string of bits obtained by setting the bit to [math] if and to if otherwise.
Then and so .
Regardless of the increase of , can be computed directly from two -bit sequences and .
We show that there is an algorithm that computes for all by storing only and for .
We first discuss how for can be obtained from and . By definition,
[TABLE]
Note that we exclude those with in the subtracted set since these values are less than by Proposition 5. Also note that can be obtained from by removing the first (smallest) entry and adding at the end. Equivalently, can be obtained from string by removing the leftmost digit and adding to the rightmost end before setting the -th digit as [math] if , leaving other digits as they were. Note that there is no need of storing as it can be computed from and .
We next discuss how can be computed inductively on the first entry, starting from . For this case, is the string of s. For , we have
[TABLE]
Therefore, can be obtained from by removing the leftmost digit and adding to the rightmost end before setting the -th digit as [math] if , leaving other digits as they were. Note that there is no need to store since it can be computed from and .
Thus, can be computed on a finite state machine that requires storing and for . After that we replace stored data by increasing the second entry by 1 and compute and so on. This finite state machine requires O states each of which needs at most bits. Using this finite state machine, we can compute the sequence . Since the finite state machine eventually repeats, the sequence is ultimately periodic and so the sequence is ultimately additively periodic. ∎
The following result means every row (column) in the expanded table of Table 1 contains exactly one Sprague-Grundy value for every .
Proposition 6**.**
For given nonnegative integers and , there exists exactly one such that . Moreover, Proposition 5 implies .
Proof.
Let . Consider the position . The lower bound in Proposition 5 gives , implying the existence of some such that either or . The first case cannot hold as by Proposition 5 and so the second case holds. Let , we have as required. ∎
4.5. The ultimate periodicity of Sprague-Grundy values
We end this section with a conjecture on the ultimate periodicity of the values on diagonals parallel to the main diagonal.
Conjecture 1**.**
The sequence is ultimately periodic.
As examples, the sequence appears to be ultimately periodic with pre-period length and period length . Its first 100 values, where the first period is bold, are
5, 6, 9, 9, 3, 3, 5, 5, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4, 3, 3, 4, 4
The sequence appears to be ultimately periodic with pre-period length and period length . Its first 400 values are
3, 8, 10, 10, 4, 4, 4, 19, 6, 6, 5, 5, 5, 6, 10, 6, 5, 5, 5, 6, 6, 8, 5, 5, 5, 8, 8, 11, 5, 5, 5, 8, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 9, 5, 5, 5, 8, 9, 8, 5, 5, 5, 9, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 8, 5, 5, 5, 9, 8, 8, 5, 5, 5, 8, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 8, 5, 5, 5, 8, 8, 10, 5, 5, 5, 8, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 10, 5, 5, 5, 8, 10, 8, 5, 5, 5, 10, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 8, 5, 5, 5, 9, 8, 8, 5, 5, 5, 8, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 8, 5, 5, 5, 8, 8, 10, 5, 5, 5, 8, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 9, 5, 5, 5, 8, 9, 8, 5, 5, 5, 9, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 8, 5, 5, 5, 9, 8, 8, 5, 5, 5, 8, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 8, 5, 5, 5, 8, 8, 10, 5, 5, 5, 8, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 10, 5, 5, 5, 8, 10, 8, 5, 5, 5, 10, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 8, 5, 5, 5, 9, 8, 8, 5, 5, 5, 8, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 8, 5, 5, 5, 8, 8, 10, 5, 5, 5, 8, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 9, 5, 5, 5, 8, 9, 8, 5, 5, 5, 9, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 8, 5, 5, 5, 9, 8, 8, 5, 5, 5, 8, 6, 6, 5, 5, 5, 6, 8, 6, 5, 5, 5, 6, 6, 8, 5, 5, 5, 8, 8, 10, 5, 5, 5, 8, 6, 6, 5, 5, 5, 6, 8, 6.
5. Further questions
We are interested in the following questions for further study.
- (1)
Formulate the Sprague-Grundy function for 2-Star Nim and generally -Star Nim. 2. (2)
More generally, formulate the Sprague-Grundy function for Star Silver Dollar with at most two tokens on each trip (not all even, not all odd).
Having opened up the study of nearly disjunctive sums obtained by identifying the first cell of each of a number of strips for Nim or Silver Dollar, it is natural to ask what happens when more cells are identified. What if cells are identified? What can be said about computation of the Sprague-Grundy function, when is held constant? What if the cells are identified in a different order – for example, with two strips, cells 0 and 1 of the first strip are identified with cells 1 and 0, respectively, of the second strip?
Given impartial games , their nearly disjunctive sum is played as for the disjunctive sum, except that, if a player moves in so that the resulting position in is a -position for , then neither player can ever make any move in any () that gives a -position for .
Acknowledgement**.**
We thank Mr Kevin Bicknell at La Trobe University for his support with the diagrams of the paper.
Appendix A Some Maple code
We include the Maple code for , Nim-sum, 2-Star Nim, and Star Silver Dollar of positions . The first two functions are recalled in the last two.
A.1. “mex”
mex := proc (S) local i; if S = {} then return 0 else for i from 0 to max(S)+1 do if not i in S then return i end if end do end if end proc
A.2. Nim-sum of two values up to 127
ns := proc (n, m) local a, b, c, i; a := convert(n, binary)+convert(m, binary); b[1] := floor((1/10000000)a); b[2] := floor((1/1000000)a-10b[1]); b[3] := floor((1/100000)a-100b[1]-10b[2]); b[4] := floor((1/10000)a-1000b[1]-100b[2]-10b[3]); b[5] := floor((1/1000)a-10000b[1]-1000b[2]-100b[3]-10b[4]); b[6] := floor((1/100)a-100000b[1]-10000b[2]-1000b[3] - 100b[4]-10b[5]); b[7] := floor((1/10)a-1000000b[1]-100000b[2]-10000b[3] -1000b[4]-100b[5]-10b[6]); b[8] := a-10000000b[1]-1000000b[2]-100000b[3]-10000b[4] -1000b[5]-100b[6]-10b[7]; for i to 8 do b[i] := mod(b[i], 2) end do; return 128b[1]+64b[2]+32b[3]+16b[4]+8b[5]+4b[6]+2b[7]+b[8]
end proc
A.3. 2-Star Nim
Texts after # are comments.
SN2 := proc (a, b) local i, j, k, g, S;
#defining values for positions with one token in zero square for i to b do g[0, i] := i-1; g[i, 0] := i-1 end do;
#recursive calculation for i to a do for j to b do S := {}; for k from 0 to i-1 do #move from one strip S := ‘union‘(S, {g[k, j]}) end do; for k from 0 to j-1 do #move from one strip S := ‘union‘(S, {g[i, k]}) end do; g[i, j] := mex(S) end do end do;
return g[a, b]
end proc
A.4. 3-Star Silver Dollar of position ([a], [b], [c,d,e])
S113 := proc (alpha, beta, gamma, h, i) local l, o, t, u, v, z, g, Omega;
#recursively assign values for positions ([0], [0], [t,u,v]) for t from 0 to gamma do for u from t+1 to h do for v from u+1 to i do if t = 0 then g(0, 0, t, u, v) := v-u-1 else g(0, 0, t, u, v) := ns(t-1, v-u-1) end if end do end do end do;
#recursively assign values for positions ([l], [0], [t,u,v]) for l to alpha do for t from 0 to gamma do for u from t+1 to h do for v from u+1 to i do if t = 0 then g(l, 0, t, u, v) := ns(l-1, v-u-1) else g(l, 0, t, u, v) := ns(ns(l-1, t-1), v-u-1) end if end do end do end do end do;
#recursively assign values for positions ([0], [o], [t,u,v]) for o to beta do for t from 0 to gamma do for u from t+1 to h do for v from u+1 to i do if t = 0 then g(0, o, t, u, v) := ns(o-1, v-u-1) else g(0, o, t, u, v) := ns(ns(o-1, t-1), v-u-1) end if end do end do end do end do;
#recursively assign values for positions ([l], [o], [0,u,v]) for l to alpha do for o to beta do for u to h do for v from u+1 to i do g(l, o, 0, u, v) := ns(ns(l-1, o-1), v-u-1) end do end do end do end do;
#recursively calculate values for positions ([l], [o], [t,u,v]) for l to alpha do for o to beta do for t to gamma do for u from t+1 to h do for v from u+1 to i do Omega := {};
#move from the strip [l]
for z from 0 to l-1 do
Omega := ‘union‘(Omega, {g(z, o, t, u, v)})
end do
#move from the strip [o]
for z from 0 to o-1 do
Omega := ‘union‘(Omega, {g(l, z, t, u, v)})
end do;
#move token t from the strip [t,u,v]
for z from 0 to t-1 do
Omega := ‘union‘(Omega, {g(l, o, z, u, v)})
end do
#move token u from the strip [t,u,v]
if 1 < u-t then
for z from t+1 to z-1 do
Omega := ‘union‘(Omega, {g(l, o, t, z, v)})
end do
end if
#move token v from the strip [t,u,v]
if 1 < v-u then
for z from u+1 to v-1 do
Omega := ‘union‘(Omega, {g(l, o, t, u, z)})
end do
end if
g(l, o, t, u, v) := mex(Omega)
end do
end do
end do
end do
end do
return g(alpha, beta, gamma, h, i)
end proc;
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] M.H. Albert, R.J. Nowakowski, D. Wolfe, Lessons in play: An introduction to combinatorial game theory, second ed., A K Peters Ltd., Wellesley, MA, 2007.
- 2[2] E.R. Berlekamp, J.H. Conway, R.K. Guy, Winning ways for your mathematical plays. Vol. 1 – 4, second ed., A K Peters Ltd., Natick, MA, 2001-2004.
- 3[3] U. Blass, A.S. Fraenkel, The Sprague-Grundy function for Wythoff’s game, Theoret. Comput. Sci. 75 (1990) 311–333.
- 4[4] C.L. Bouton, Nim , a game with a complete mathematical theory, Ann. of Math. 3 (1901/02) 35–39.
- 5[5] J.H. Conway, N.J. A. Sloane, Lexicographic codes: error-correcting codes from game theory. IEEE Trans. Inform. Theory 32 (1986) 337– 348.
- 6[6] J.H. Conway, On numbers and games, second ed., A K Peters Ltd., Natick, MA, 2001.
- 7[7] A. Dress, A. Flammenkamp, N. Pink, Additive periodicity of the Sprague-Grundy function of certain Nim games, Adv. in Appl. Math. 22 (1999) 249–270.
- 8[8] E. Duchêne, A.S. Fraenkel, R.J. Nowakowski, M. Rigo, Extensions and restrictions of Wythoff’s game preserving its 𝒫 𝒫 \mathcal{P} -positions, J. Combin. Theory Ser. A 117 (2010) 545–567.
