Fact-checked by Grok 2 weeks ago

Nim

Nim is a two-player impartial combinatorial in which players alternate turns removing one or more objects from a heap among several distinct heaps, with the objective of taking the last object to win under the normal play convention. The game is typically played with heaps of stones, matches, or similar items, and a player may remove any positive number of objects from exactly one heap per turn, but cannot touch multiple heaps simultaneously. A is losing for the about to move if all heaps are empty, as no legal move is possible. Variants of Nim have existed since ancient times and are believed to have originated in China, where a similar game called jiǎnshízǐ (translated as "pick up pebbles") was played. This early form involved collecting stones or pebbles, and analogous games spread to Europe by at least the 16th century, often under names like "the game of Kayles" or other subtraction-based variants. The modern version of Nim, as a multi-heap game with complete mathematical analysis, was formalized and named by American mathematician Charles L. Bouton in his 1901 paper published in The Annals of Mathematics, where he provided a rigorous theory based on binary representations of heap sizes. Bouton's analysis revealed that the game's outcome is determined by the bitwise (XOR) of the heap sizes, known as the Nim-sum; if the Nim-sum is zero at the start, the second player has a winning strategy by always responding to maintain a zero Nim-sum, while a non-zero Nim-sum favors the first player. This digital method, or "Nimbers," forms the foundation of (CGT), enabling the evaluation of complex s as sums of simpler Nim s. The Sprague-Grundy theorem, independently developed in by Roland Sprague and Patrick Grundy, generalized Bouton's insights, proving that every under normal play is equivalent to a Nim of a certain size (its Grundy number), thus establishing Nim as the example in CGT. Beyond the standard rules, Nim has numerous variants, including misère Nim (where taking the last object loses), subtraction Nim (limiting removable objects), and multi-player extensions, which have influenced fields from algorithms to . Its simplicity yet strategic depth has made Nim a staple in mathematical education and a precursor to broader applications in game-solving software and .

Gameplay Fundamentals

Basic Rules

Nim is an impartial combinatorial for two , meaning both have access to the same set of possible moves from any given position. It is played under the normal play convention, in which the player who makes the last move wins. The setup consists of multiple distinct , each containing a positive number of objects such as stones, matches, or coins; the number of and their initial sizes can vary, for example, three with 3, 5, and 7 objects respectively. Players alternate turns, beginning with the first player. On each turn, a player must select exactly one and remove any positive number of objects from it—at least one, but up to the entire contents of that heap. Removing objects from more than one in a single turn is not permitted. The game's objective is to force the opponent into a with no legal moves available, which occurs when all heaps are empty. The player unable to move on their turn loses. In , each heap functions as an independent , and the overall is the disjunctive sum of these subgames. A variant known as misère Nim reverses the winning condition so that the player making the last move loses, though standard Nim adheres to normal play. A complete winning strategy for normal play exists, determined by the nim-sum of the heap sizes, though its details involve sums.

Illustrative Example

Consider a simple instance of Nim featuring three distinct s containing 1, 3, and 5 stones, respectively. Player A begins the game, and players alternate turns, with each required to select exactly one and remove at least one stone from it (but not from multiple s in a single turn). A common beginner mistake is attempting to remove stones from more than one at once, which is illegal and would result in an invalid move. The initial position can be represented as:
  • Heap 1: 1 stone
  • Heap 2: 3 stones
  • Heap 3: 5 stones
Player A makes a suboptimal choice by removing the single stone from 1, emptying it entirely and leaving the position as:
  • 1: 0 stones
  • Heap 2: 3 stones
  • 3: 5 stones
This move reduces Player A's options prematurely while handing Player B a stronger configuration. Player B then removes 2 stones from 3, resulting in:
  • Heap 1: 0 stones
  • Heap 2: 3 stones
  • Heap 3: 3 stones
Player A next clears 2 by removing all 3 stones, leading to:
  • Heap 1: 0 stones
  • Heap 2: 0 stones
  • Heap 3: 3 stones
Player B responds by taking all 3 remaining stones from Heap 3, emptying the board and securing the win. In this playthrough, Player A's suboptimal decisions—such as fully depleting small heaps early—allow Player B to control the endgame and take the last stones. The all-empty board represents a losing position for the player whose turn it would be next, as no legal moves remain. This example illustrates how choices in Nim can lead to an intuitive sense of advantageous versus disadvantageous positions through actual gameplay.

Historical Context

Ancient Origins

Variants of the game Nim have roots in ancient , where a similar pastime known as jiǎn shízi (picking up stones) was played using pebbles or small objects arranged in heaps. This early form, involving alternate removals from the heaps, is believed to date back to ancient times, though the precise origins remain obscure. The game was typically recreational, played informally without structured rules or strategic analysis, often as a social activity among children or adults using readily available materials like stones or sticks. Possible antecedents to Nim-like games appear in other ancient cultures, where subtraction-based or object-taking pastimes may have existed, though direct historical evidence is limited and debated among scholars. By the early , Nim variants had reached , manifesting as folk "taking games" that spread through oral traditions across rural and urban communities. In the 18th and 19th centuries, these evolved into popular pastimes using matchsticks, coins, or beans, particularly in pubs where they fostered social bonding and light wagering. The simplicity of these folk iterations—requiring no specialized equipment—ensured their endurance as casual diversions until formal study in the early .

Modern Mathematical Analysis

The modern mathematical analysis of Nim began in the early 20th century with Charles L. Bouton's seminal work, which provided the first complete winning strategy for the game and laid the groundwork for theory. Bouton, an associate professor at , analyzed Nim in his 1901–1902 paper, demonstrating that the game's outcome depends on the binary digital representation of pile sizes and their (XOR) combination, known as the nim-sum. This approach not only solved standard Nim but also introduced a systematic method for determining winning and losing positions in impartial games, marking a pivotal shift from recreational puzzle to rigorous . Bouton's insights directly influenced subsequent developments in the and , particularly the Sprague-Grundy theorem, which generalized his Nim strategy to arbitrary sums of . Independently formulated by Roland Sprague in 1936 and Patrick M. Grundy in 1939, the theorem assigns a (Grundy number) to each game position as the minimum excludant (mex) of the nimbers of its options, proving that any is equivalent to a Nim heap of that size. Sprague's work, published in German as "Über mathematische Kampfspiele," extended Bouton's XOR method to composite games, while Grundy's "Mathematics and Games" in the Cambridge University magazine formalized the recursive assignment of values, enabling analysis of complex game combinations beyond Nim heaps. These contributions established Nim as the canonical example in , bridging isolated game solutions to a unified framework. Post-World War II, Nim's mathematical significance expanded through popularization and computational applications, solidifying its role in both theoretical and practical contexts. The 1982 book Winning Ways for Your Mathematical Plays by Elwyn R. Berlekamp, John H. Conway, and synthesized decades of progress, using Nim as a foundational tool to explore advanced impartial games, misère variants, and surreal numbers, thereby influencing generations of mathematicians and computer scientists. Computationally, Nim featured prominently in early and programming education; the 1951 Nimrod, a specialized digital computer exhibited at the , implemented Bouton's strategy in hardware to play against humans, demonstrating real-time XOR calculations and marking one of the first purpose-built computing devices for game-playing.

Strategy for Standard Nim

Winning and Losing Positions

In standard Nim under normal play convention—where the player unable to move loses—a game is classified as either a winning or a losing based on optimal play by both participants. A losing , often denoted as a P- (indicating the previous player wins), is one in which every possible legal move leaves the opponent in a winning , thereby guaranteeing the current player's defeat if the opponent plays perfectly. Conversely, a winning , or N- (next player wins), is one from which the current player can make at least one move that forces the opponent into a losing , securing victory with flawless subsequent play. This underpins the strategic analysis of Nim and stems from foundational work in . The simplest examples illustrate these concepts clearly. The terminal position, consisting of all heaps empty (zero objects in every heap), is a losing position, as the player to move has no options and thus loses immediately. For a single-heap game, a heap of size zero is losing, while any heap of size greater than zero is winning, since the player can remove all objects in one move, leaving the empty position for the opponent. In multi-heap configurations, the all-zero state remains losing, but other setups vary: for instance, two heaps of equal non-zero size (e.g., one heap of 3 and another of 3) constitute a losing position, as any reduction in one heap permits the opponent to mirror the move in the other, preserving equality and eventually forcing the first player into the terminal loss. This classification exhibits a recursive structure, evaluated backward from the known terminal losing . Starting with , each prior is assessed by examining all reachable subsequent states: if any leads to a losing , the current one is winning; if all lead to winning positions, it is losing. This inductive process, applied to increasingly larger configurations, reveals patterns and builds strategic without requiring exhaustive computation for every case. For small instances, such as two heaps of unequal sizes (e.g., 2 and 4), the first player can win by reducing the larger heap to the smaller, shifting to a losing position for the second player. Such examples highlight how balanced or symmetric setups often prove disadvantageous, guiding players toward disruptive moves that unbalance the game in their favor. The precise identification of these positions in general relies on tools like the nim-sum, as detailed in the following section.

The Nim-Sum and XOR Calculation

In standard Nim, the nim-sum provides a computational method to evaluate the game's position by combining the heap sizes using their representations. Specifically, the nim-sum is obtained by performing a bitwise (XOR) operation on the forms of all sizes, where XOR compares corresponding bits and results in 1 if the bits differ and 0 if they are the same. This operation, equivalent to summing the binary digits in each column modulo 2 (i.e., counting the number of 1s in each bit position and taking the ), was introduced by L. Bouton in his analysis of Nim. A position in Nim is a winning position (N-position) for the player about to move if the nim-sum is nonzero, meaning the first player can force a win with optimal play; conversely, it is a losing (P-position) if the nim-sum is zero, as any move will leave a nonzero nim-sum for the opponent. For heaps of sizes a_1, a_2, \dots, a_n, the nim-sum is denoted as a_1 \oplus a_2 \oplus \dots \oplus a_n. To illustrate, consider heaps of sizes 3, 5, and 7. In , these are 011, , and 111, respectively (padded to three bits for alignment). First, XOR 011 and : bit by bit, 0⊕1=1, 1⊕0=1, 1⊕1=0, yielding 110 ( 6). Then XOR 110 with 111: 1⊕1=0, 1⊕1=0, 0⊕1=1, resulting in 001 ( 1), which is nonzero. Thus, this is an N-position. To find a winning move from an N-position, the player selects one and reduces its size to a value that makes the overall nim-sum zero. If the current nim-sum is s \neq 0, for a chosen a_i, the target size is a_i \oplus s, provided this is less than a_i (ensuring a valid reduction). Continuing the example with 3, 5, 7 and s = 1 (001 in ), targeting the of 7 (111): 111 ⊕ 001 = 110 ( 6), so reducing the 7- to 6 yields new 3, 5, 6. Their nim-sum is 011 ⊕ ⊕ 110 = 011 ⊕ = 110, then 110 ⊕ 110 = 000, a P-position. The following table shows nim-sums (XOR results) for small heap combinations, using binary representations up to 3 bits (values 0–7), to demonstrate the operation's pattern:
Heap A (binary)Heap B (binary)Nim-sum (binary, decimal)
000 (0)000 (0)000 (0)
001 (1)001 (1)000 (0)
001 (1)010 (2)011 (3)
011 (3)101 (5)110 (6)
110 (6)111 (7)001 (1)
This table highlights how XOR balances bits to zero out the sum in P-positions.

Mathematical Foundations

Impartial Game Theory

Impartial games constitute a core category within combinatorial game theory, defined as perfect-information, two-player games where the set of legal moves from any given position is identical for both players, regardless of who is to move. This symmetry contrasts with partizan games, in which the available moves can differ between the players. The framework for analyzing impartial games under normal play convention—where the last player to move wins—was established independently by mathematicians Roland P. Sprague and Patrick M. Grundy in the late 1930s. Central to the theory is the concept of the Grundy number, also called the , which assigns a non-negative value to each game to determine its strategic to Nim heaps. For a G, the Grundy number g(G) is computed as the minimum excludant (mex) of the Grundy numbers of all positions reachable from G in one legal move: g(G) = \mex \left\{ g(H) \mid H \text{ is a position reachable from } G \right\}, where the mex of a set of non-negative integers is the smallest non-negative integer absent from that set, and the terminal position (with no moves) has g(0) = 0. A position with g(G) = 0 is a losing position (P-position) for the player about to move under optimal play, while g(G) > 0 indicates a winning position (N-position). Many impartial games are structured as disjunctive sums of independent components, such as multiple heaps or subgames, where a player's turn involves selecting exactly one component and making a legal move within it, leaving the others intact. The Sprague-Grundy theorem asserts that the Grundy number of the overall sum is the bitwise (XOR) of the Grundy numbers of the individual components: g(G_1 + G_2 + \cdots + G_k) = g(G_1) \oplus g(G_2) \oplus \cdots \oplus g(G_k). This reduction enables the analysis of complex sums by treating them as equivalent to a single Nim game whose heap sizes correspond to the nimbers. Nim exemplifies the prototype, as the of a single of size n is precisely n, simplifying the evaluation of multi-heap positions to the XOR of heap sizes. To illustrate, consider the basic *1, a with one move to the terminal 0; its is g(*1) = \mex\{0\} = [1](/page/1). The *1 + *1 yields $1 \oplus 1 = [0](/page/0), a P-position where the second player wins. In contrast, *1 + *2, with g(*2) = \mex\{0, [1](/page/1)\} = 2, gives $1 \oplus 2 = 3 > [0](/page/0), an N-position favoring the first player. Such examples demonstrate how nimbers and XOR operations classify positions across . This theoretical structure provides the foundation for determining winning strategies in impartial games like , where a nonzero overall signals a first-player victory under optimal play.

Bouton's Theorem

Bouton's theorem provides the foundational winning strategy for the game of under normal play convention, where the last player to move wins. Formally, in a consisting of heaps of sizes n_1, n_2, \dots, n_k, the first player has a winning strategy if and only if the nim-sum \bigoplus_{i=1}^k n_i \neq 0, where \oplus denotes the bitwise (XOR) operation applied to the binary representations of the heap sizes. This nim-sum serves as the key determining the 's status as winning (non-zero nim-sum) or losing (zero nim-sum) for the player about to move. Within the broader context of impartial game theory, Bouton's theorem aligns directly with the Sprague-Grundy theorem. Specifically, the Grundy number (or nimber) of a single Nim heap of size n is exactly n itself, since the possible moves from such a heap lead to positions with Grundy numbers $0, 1, \dots, n-1, and the minimum excludant (mex) of these is n. The Grundy number of the combined position is then the XOR of the individual heap Grundy numbers, yielding the nim-sum as the overall game's value. The implications of Bouton's theorem extend beyond Nim, establishing it as a cornerstone for analyzing s. By the Sprague-Grundy theorem, every under normal play is equivalent to a Nim (or of s) whose size matches the game's Grundy number, allowing complex positions to be reduced to Nim equivalents for strategy determination. Named after mathematician Charles L. Bouton, who derived the result in his 1901 analysis, the theorem was later generalized by Roland Sprague in 1935 and Patrick Michael Grundy in 1939 to encompass all such games. A direct illustrates the theorem's application: a with two heaps of equal size n has nim-sum n \oplus n = 0, rendering it a losing for the first , as any move leaves a non-zero nim-sum for the opponent.

Proof of the Winning Strategy

The proof of Bouton's theorem proceeds by on the total number of objects across all heaps in the . Consider the base case of the empty , where all sizes a_1 = a_2 = \dots = a_n = 0. Here, the nim-sum s = 0 \oplus 0 \oplus \dots \oplus 0 = 0, and the is losing for the current player since no legal moves are possible. For the inductive , assume the holds for all Nim positions with fewer total objects than the current (a_1, a_2, \dots, a_n), where \sum a_i = m > 0. First, suppose the nim-sum s = a_1 \oplus a_2 \oplus \dots \oplus a_n = 0. Any legal move selects some i and replaces a_i with some k where $0 \leq k < a_i. The resulting nim-sum is s' = s \oplus a_i \oplus k = 0 \oplus a_i \oplus k = a_i \oplus k. Since k \neq a_i, it follows that a_i \oplus k \neq 0, so s' \neq 0. By the inductive , this new (with fewer total objects) is winning for the opponent. Thus, every move from a with s = 0 leads to a winning for the opponent, confirming that such positions are losing. Now suppose s \neq 0. To show this is a winning position, it suffices to exhibit a move to a position with nim-sum 0. Let s be expressed in binary; identify the highest bit position (say, the $2^b place) where s has a 1. There must exist at least one heap i where a_i also has a 1 in this bit position, because the nim-sum s results from an odd number of such 1s across all heaps in that bit (due to the properties of bitwise XOR). For this i, define k = a_i \oplus s. Since XORing a_i with s flips all bits of a_i where s has 1s, and the highest such bit in s is also 1 in a_i, the resulting k will have 0 in that highest bit while preserving or reducing lower bits, ensuring k < a_i. The new nim-sum after replacing a_i with k is s' = s \oplus a_i \oplus k = s \oplus a_i \oplus (a_i \oplus s) = s \oplus s = 0. This new position has fewer total objects and nim-sum 0, so by the inductive hypothesis it is losing for the opponent. Thus, positions with s \neq 0 are winning. This establishes Bouton's theorem by . In the broader framework of impartial games, the result aligns with the Sprague-Grundy theorem, where the Grundy number g of a single of size n satisfies g(n) = \ mex\{g(0), g(1), \dots, g(n-1)\}. Since moves from a heap of n lead to heaps of sizes 0 through n-1, and assuming by that g(j) = j for j < n, the mex of \{0, 1, \dots, n-1\} is n. The Grundy number of a multi-heap position is then the XOR of the individual heap Grundy numbers, which equals the nim-sum, and the position is losing this value is 0.

Variations

Misère Nim

Misère Nim is a variant of the game of Nim in which the player who removes the last object loses, while all other rules remain the same: players alternate turns removing any positive number of objects from a single heap. This misère convention alters the endgame dynamics but leaves the overall structure largely intact for most positions. The optimal strategy for misère Nim follows the nim-sum (bitwise XOR of heap sizes) calculation from standard Nim as long as at least one heap has more than one object. In such positions, a position is losing if the nim-sum is zero and winning otherwise, with the winning move reducing the nim-sum to zero. However, when all heaps have size at most one (i.e., consisting only of empty heaps and heaps of size one), the strategy diverges: the position is winning if the number of size-one heaps is even and losing if odd. In this endgame, the winning move is to remove an entire size-one heap, leaving an odd number of them for the opponent. This adaptation of Bouton's theorem for normal-play Nim applies unchanged when the largest heap exceeds one, but reverses the winning condition in the all-small-heaps case relative to normal play, where an even number of size-one heaps would be losing. For example, a single of size one is a losing position, as the player must take the last object and lose. With two heaps of size one (even), the first player wins by removing one heap, leaving a single size-one (odd, losing for the opponent). With three heaps of size one (odd), any move leaves two (even, winning for the opponent), so it is losing. The proof of this relies on on the total number of objects. For positions with a larger than one, the inductive assumes the strategy holds for subpositions with fewer objects, confirming that moves to nim-sum zero lead to losing positions under misère rules, as the game cannot immediately enter the all-small-heaps phase without allowing a response. The all-small-heaps case is verified directly: it reduces to a simple equivalent to Kayles or Dawson's Chess in misère form, where optimal play ensures the player facing an odd number of isolated objects loses by being forced to leave an even number. This separation handles the misère endgame without contradicting the normal-play analysis elsewhere.

Subtraction and Counting Games

Subtraction games constitute a class of single-heap impartial games that restrict the number of objects a player can remove to a predefined S of positive s. From a heap of n objects, a legal move consists of subtracting s objects where s \in S and n - s \geq 0; the player unable to move loses, or equivalently, the player taking the last object wins under normal play. The analysis of these games relies on Grundy numbers, defined as g(n) = \ mex \{ g(n - s) \mid s \in S, n - s \geq 0 \}, where mex denotes the minimum excludant (smallest non-negative not in the set). For finite S, the sequence g(n) is eventually periodic, enabling the identification of periodic winning and losing positions. A prototypical example is the subtraction game with S = \{1, 2, 3\}, where players may remove up to three objects per turn. Here, the Grundy numbers follow a period of 4: g(n) = n \mod 4. The P-positions (previous-player-win positions, or losing positions for the current assuming optimal play) occur when g(n) = 0, i.e., when n \equiv 0 \pmod{4}. The first player wins from any n \not\equiv 0 \pmod{4} by moving to a multiple of 4, forcing the opponent into N-positions thereafter. The 21 game exemplifies this variant, beginning with a heap of 21 objects and S = \{1, 2, 3\}. Since $21 \mod 4 = 1, it is an N-position; the first secures victory by removing 1 object to leave 20 (a P-position), then responds to the opponent's move of k (1 ≤ k ≤ 3) by removing $4 - k to restore a multiple of 4. This strategy ensures the first player always leaves the opponent with multiples of 4, culminating in taking the last objects from 4, 3, 2, or 1. Another popular counting game is the game of 100, a game with S = \{1, 2, \dots, 10\} starting from 100 objects (equivalently, players alternately add 1 to 10 toward a total of 100, with the one reaching exactly 100 winning). The Grundy numbers are periodic with period 11, given by g(n) = n \mod 11, so P-positions are multiples of 11. With $100 \mod 11 = 1 (as $11 \times 9 = 99), the first player wins by removing 1 to leave 99, then counters any opponent removal of k (1 ≤ k ≤ 10) with $11 - k to maintain multiples of 11. In general, for subtraction games where S = \{1, 2, \dots, m\}, the P-positions are precisely those n \equiv 0 \pmod{m+1}, as the periodicity aligns with this modulus, allowing the first player to win from starting positions not congruent to 0 modulo m+1 by always moving to such positions. These games serve as foundational single-heap cases that generalize to multi-heap through the Sprague-Grundy theorem.

Rule-Modified Multi-Heap Games

Rule-modified multi-heap games in Nim introduce alterations to the standard removal rules, such as constraints on the number of objects taken relative to prior turns or requirements to interact with specific heaps, while preserving the multi-heap setup and impartial nature. These variants require adapted analyses using Sprague-Grundy theorem, where Grundy numbers for positions are computed based on modified move options, often leading to distinct winning strategies beyond the standard nim-sum. Seminal works, like those by and later researchers, provide the foundational strategies for many such games, emphasizing representations or positional symmetries for determining P-positions. Greedy Nim, as defined by and Nowakowski, restricts players to removing at least one object from a single largest heap on each turn, with multiple largest heaps treated symmetrically. This rule alters the game's dynamics by forcing focus on maximal heaps, preventing reductions in smaller ones until ties occur. The Grundy number for a single of size n in this variant is 0 if n = 0, and otherwise follows a pattern where positions are evaluated based on the of maximal heaps in multi-heap configurations. Specifically, a is a P-position if the number of heaps of maximum size is even; the first player can then to maintain this parity, ensuring a win for the second player in such cases. For example, with two heaps of size 3, the even count makes it losing for the starter, as any move reduces one to below 3, leaving an odd number of maxima for the opponent to equalize. A related rule modification appears in progressive variants, where each player must remove strictly more objects than the opponent did in the previous turn, starting with the first player taking any positive number from one heap. This escalating threshold changes the game into one with history-dependent moves, requiring Grundy computations that incorporate the prior removal size as part of the position state. The strategy involves calculating modified Grundy values for heap sizes under increasing minimum removal constraints, leading to thresholds where small heaps become inaccessible after early large moves. For instance, if the first player removes 1 from a heap of 5, the second must remove at least 2, potentially forcing the game toward misère-like ends if totals are low; winning play balances escalation to exhaust options without violating the rule. Moore's Nim, also known as index-k Nim, allows players to select up to k heaps and remove any positive number from each chosen heap in a single turn, generalizing standard Nim (k=1). Proposed by , this variant expands move flexibility, particularly for larger k, and its analysis relies on decomposition of sizes. A position is a P-position if and only if, for every bit position in the representations of the sizes, the number of heaps with a 1 in that bit is congruent to 0 (k+1). To win, a player identifies a non-zero "generalized nim-sum" across bit columns and adjusts up to k heaps to restore the modulo condition. For example, with k=2 and heaps of sizes 1 ( 01), 2 (10), and 3 (11), the bit 0 has two 1s (not 0 mod 3), and bit 1 has two 1s (not 0 mod 3), making it an N-position; a winning move might reduce the size-3 heap to 0, leaving bits balanced mod 3. Circular Nim arranges heaps in a , where a move involves selecting k consecutive heaps and removing any positive number from each, introducing adjacency dependencies that break heap . Introduced and analyzed by Dufour and Heubach, this variant uses the Sprague-Grundy theorem on the circular structure, computing overall Grundy numbers as the mex over options from rotated subpositions. For fixed small n (number of heaps) and k, P-positions are characterized by periodic patterns in heap sizes, such as all heaps equal for certain (n,k) pairs like n=4, k=2, where the Grundy number is 0. Strategies involve modified XOR-like sums accounting for circular symmetry; for instance, in CN(7,4), specific sequences like (1,0,1,0,1,0,1) are P-positions due to no viable consecutive reductions leading to a zero-Grundy state, as detailed in exhaustive computations for n ≤ 8. These games highlight how topological rules amplify complexity, with Grundy values often periodic but requiring case-by-case verification for larger parameters.

Geometric and Structural Variants

Geometric variants of Nim incorporate spatial structures, such as graphs or lattices, into the game board, where moves are constrained by the of the structure rather than heaps. In these games, the position of heaps relative to one another influences legal moves, often requiring players to remove objects from connected components. This adds a layer of strategic depth, as the affects the independence of subgames, analyzed through extensions of impartial game theory. Graph Nim places heaps of tokens on the vertices of an undirected graph, making the game impartial under normal play convention. The game maintains a current position on a vertex. A move consists of selecting the current vertex or an adjacent vertex and removing any positive number of tokens from the heap at the selected vertex, with other heaps unchanged; the current position then updates to the selected vertex. The game ends when no tokens remain on allowable vertices, with the last player to move winning. Strategies rely on computing Grundy numbers for graph positions, defined as the minimum excludant (mex) of the Grundy numbers of positions reachable in one move; for example, in a path graph of three vertices with one token each, the central vertex's connectivity alters the overall nimber compared to disjoint heaps. This variant is PSPACE-complete to determine the winner, highlighting computational challenges in complex graphs. Higher-dimensional Nim extends the game to multidimensional grids or fractal-like structures, such as analogs of the Sierpinski triangle. In one formulation, the board is a high-dimensional Sierpinski gasket, where positions correspond to points in the structure, and moves remove a token from a chosen position and all "dominated" positions in lower dimensions, akin to subtracting along coordinate axes in a . For instance, three-dimensional Wythoff Nim generalizes the classic two-pile Wythoff game to three piles, allowing removals from one pile, two piles equally, or all three equally, with winning positions determined by Beatty sequences in higher dimensions. These variants preserve the XOR-based strategy of standard Nim but adapt it to the partial order of the geometric space, yielding Grundy numbers that reflect dimensional symmetries. Building Nim introduces a dynamic structural element through a two-stage process: first, players alternately place a fixed number of tokens onto an initial of stacks (heaps are created or augmented during this building phase), followed by Nim play on the resulting . With n tokens and up to m stacks, the building stage allows merging or splitting implicitly via placement rules, altering sizes before removal begins. Analysis shows that the overall Grundy number combines the building phase's options with the Nim phase's nimbers; for small n and m, optimal building leads to balanced heaps that force a second-player win under normal play. This variant emphasizes foresight in structure formation, distinct from static geometric boards. Candy Nim overlays an economic dimension onto standard heaps by treating tokens as valued candies, where the primary goal is to take the last candy (normal play), but players secondarily aim to maximize the total candies they collect across all moves. Each removal carries a "cost" in terms of opportunity, as players weigh immediate gains against preserving winning positions; for example, in a heap of size k, the first player takes all k to win both objectives. Optimal play employs modified Grundy numbers that incorporate a scoring , balancing misère-like last-move incentives with accumulation, often resulting in selective moves that sacrifice short-term gains for overall maximization. Recent research has introduced further variants, such as (2025), which generalizes normal and misère play through a scoring mechanism that rewards certain moves, and (2024), where a player eliminates one pile and may split the removed pile's stones into two non-empty piles. These developments continue to explore extensions of impartial game theory.

References

  1. [1]
    [PDF] Theory of Impartial Games - MIT
    Feb 3, 2009 · The Game of Nim. We first look at the simple game of Nim, which led to some of the biggest advances in the field of combinatorial game theory.
  2. [2]
    Combinatorial Games (Part I): The World of Piles of Stones
    The other theory of games is often referred to as Combinatorial Games. One classical game of this kind is Nim, where two players move alternately by selecting ...
  3. [3]
    Nim | Asia Society
    In China, this game is known as jianshiji, which is translated to mean "pick up pebbles." This game was known in Europe as early as the 16th century.Missing: origins | Show results with:origins
  4. [4]
    Nim - ETH Zurich
    History. The origin of the game is uncertain. Similar games are known to have existed in ancient China. The earliest reference to the game in Europe dates ...
  5. [5]
    Nim, A Game with a Complete Mathematical Theory - jstor
    BOUTON. THE game here discussed has interested the writer on account of its seem- ing complexity, and its extremely simple and complete mathematical theory.
  6. [6]
    Nim game - Archimedes Lab Project
    The theory of the Nim game was discovered by mathematics professor Charles Bouton at Harvard University in 1901. In fact, Bouton, who wanted to use the game ...
  7. [7]
    Nim - GamesCrafters - UC Berkeley
    Invented in China, Nim (meaning "to take") is played by children on small pieces of paper or by adults using coins. In 1902 it was given the name Nim by Harvard ...Missing: origins | Show results with:origins
  8. [8]
    [PDF] GAME THEORY - CMU School of Computer Science
    Here are the rules of a very simple impartial combinatorial game of removing chips from a pile of chips. (1) There are two players. We label them I and II. (2) ...
  9. [9]
    Nim -- from Wolfram MathWorld
    ### Nim Rules and Example
  10. [10]
    Nim | Brilliant Math & Science Wiki
    The only rule is that each player must take at least one object on their turn, but they may take more than one object in a single turn, as long as they all come ...
  11. [11]
    [PDF] curiosityat home - game of nim - Pacific Science Center
    Nim is a simple math game that likely originated from the Chinese game 捡石子 (jiǎn-shízi, or picking up stones), which is hundreds of years old.
  12. [12]
    Nim | Ancient Number Game | Britannica
    Oct 31, 2025 · Nim, ancient game of obscure origin in which two players alternate in removing objects from different piles, with the player who removes the last object ...
  13. [13]
    A Prehistory of Nim: The College Mathematics Journal
    Nov 28, 2017 · Summary. The first occurrence of Nim dates back to 1901 when the mathematician Charles Leonard Bouton published an article on its solution.
  14. [14]
    Towards a theory for combinatorial games
    Each position of an impartial game (standard play) is equivalent to a Nim position with bogus nim heaps. Once one has converted a game position to an equivalent ...<|control11|><|separator|>
  15. [15]
    [PDF] MACHINES DESIGNED TO PLAY NIM GAMES
    This article deals with Nim games and machines built to play against a human being between the 1940s and the. 1970s. They were designed not only to ...
  16. [16]
    [PDF] NIM Contents 1. Nim 1 2. 3–3 1 3. Winning and Losing Games 3 4 ...
    Combinatorial game theory is a mathematical theory dealing with two-player games of perfect information and no chance moves. Known to both players are the rules ...Missing: original | Show results with:original<|control11|><|separator|>
  17. [17]
    [PDF] The Game of Nim - UW-Math Wiki
    The full strategy for Nim was discovered by the mathematician Charles Bouton in 1902. His paper on Nim is considered to be the birth of combinatorial game ...<|control11|><|separator|>
  18. [18]
    [PDF] Nim, A Game with a Complete Mathematical Theory Charles L ...
    Apr 11, 2007 · Nim, A Game with a Complete Mathematical Theory. Charles L. Bouton. The Annals of Mathematics, 2nd Ser., Vol. 3, No. 1/4. (1901 - 1902), pp.
  19. [19]
    Most Wanted Solutions: Nim game strategy - Archimedes Lab Project
    To win at Nim-game, always make a move, whenever possible, that leaves a configuration with a ZERO “Nim sum”, that is with ZERO unpaired multiple(s) of 4, 2 or ...<|control11|><|separator|>
  20. [20]
    [PDF] Working Backwards: Solution
    On a hunch, let's rewrite the nim-sum table in binary. It may not be obvious, but this is also the table for bitwise XOR! That is, a binary digit of a ⊕ b is 0.
  21. [21]
    [PDF] nim magic formula
    consider t-pile nim position p = (p1,p2,...,pt) definition nim-sum(p): xor(p) = p1 ⊕ p2 ⊕ ... ⊕ pt theorem (Bouton, 1901): player-to-move wins (has winning ...Missing: calculation | Show results with:calculation
  22. [22]
    Sprague-Grundy theorem. Nim - CP-Algorithms
    Sep 16, 2024 · This theorem describes the so-called impartial two-player game, ie those in which the available moves and winning/losing depends only on the state of the game.
  23. [23]
    Misère-Form Game -- from Wolfram MathWorld
    A version of nim-like games in which the player taking the last piece is the loser. For most impartial games, this form is much harder to analyze.
  24. [24]
    [PDF] Misère games and misère quotients - The Library at SLMath
    So the strategy for misère NIM is: play exactly like in normal NIM, unless your move would leave only heaps of size 0 or 1. In that case, play to leave an.
  25. [25]
    Analysis of Misere Nim? - combinatorial game theory - MathOverflow
    Aug 1, 2011 · This is a winning position for the ... Eventually (after losing many times) I told her that (n, n+1,1) is a losing position for any n...
  26. [26]
    [PDF] The Misère Mex Mystery - Misere Games
    misère outcomes coincide. The Mis`ere Mex Mystery – p. 16/29. Page 29. Misère Nim (6). Remember the strategy for misère Nim: Play normal Nim until your move ...
  27. [27]
    [PDF] A brief conversation about subtraction games - The Library at SLMath
    In this survey we revisit FINITE SUBTRACTION, one-heap subtraction games on finite rulesets. The main purpose is to give a general overview of the.
  28. [28]
    [PDF] 21-Nim Winning and Losing Positions The Game of Nim Nim ...
    Oct 21, 2013 · On your turn, you can take 1, 2 or 3 counters. You win if you take the last counter. In a losing position, the next player will lose if her ...
  29. [29]
    Winning strategy for add game - Mathematics Stack Exchange
    Jul 12, 2021 · Two players start from 0 and alternately add a number from 1 to 10 to the sum. The player who reaches 100 wins. The winning strategy is to reach ...A game of add at most 10 - Math Stack ExchangeSum to 100 game - Math Stack ExchangeMore results from math.stackexchange.com
  30. [30]
    A Nim game played on graphs - ScienceDirect.com
    We propose a new impartial game played by two players, which can be compared to the well-known Nim game (Winning Ways for Your Mathematical Plays, ...
  31. [31]
    [PDF] A PSPACE-complete graph nim - The Library at SLMath
    NIM is a classic impartial game, being the basis of Nimbers and Sprague–. Grundy theory [8; 5]. NIM has lots of nice properties, from easy evaluation of games ...
  32. [32]
    [1805.07019] $\mathcal{P}$ Play in Candy Nim - arXiv
    May 18, 2018 · Candy Nim is a variant of Nim in which both players aim to take the last candy in a game of Nim, with the added simultaneous secondary goal of ...
  33. [33]
    Circular Nim Games | The Electronic Journal of Combinatorics
    Apr 30, 2013 · A circular Nim game is a two player impartial combinatorial game consisting of n n stacks of tokens placed in a circle. A move consists ...