Nimber Calculator

Nim-values & Sprague-Grundy

CalculatorsFreeNo Signup
4.4(641 reviews)
All Tools

Loading tool...

About Nimber Calculator

A nimber calculator for combinatorial game theory. Computes nim-addition (XOR) and nim-multiplication, Sprague-Grundy values, and analyzes Nim game positions. Shows winning/losing positions and optimal moves. Client-side.

Nimber Calculator Features

  • Nim-add (XOR)
  • Nim-multiply
  • SG values
  • Win/Lose
  • Strategy
Nimbers: the values in combinatorial game theory. Nim-addition = XOR: a⊕b. Nim position (a₁,...,aₖ): losing iff a₁⊕...⊕aₖ=0 (Sprague-Grundy). Nim-multiplication: defined recursively, forms a field GF(2^∞). Key to analyzing impartial games.

How to Use

Choose mode:

  • Nim-add: a ⊕ b (XOR)
  • Nim game: Analyze position
  • Strategy: Winning moves

Sprague-Grundy Theorem

Every impartial game position has a Grundy number G. Sum of games: G₁⊕G₂⊕...⊕Gₖ. Position is losing (P-position) iff G=0. This reduces ALL impartial games to Nim!

Nim Strategy

Current position (a₁,...,aₖ): compute S=a₁⊕...⊕aₖ. If S=0: you lose (P-position). If S≠0: find i where aᵢ⊕S < aᵢ, reduce aᵢ to aᵢ⊕S. This leaves S'=0 for opponent.

Step-by-Step Instructions

  1. 1Enter heap sizes.
  2. 2Compute nim-sum.
  3. 3Check position.
  4. 4Find winning moves.
  5. 5Play optimally.

Nimber Calculator — Frequently Asked Questions

Why does XOR determine the winner?+

XOR works because: (1) it's 0 iff all bits cancel, meaning balanced piles; (2) from any S≠0 position, you can always reach S=0; (3) from S=0, any move makes S≠0. This is the Bouton's theorem (1901).

What is the Sprague-Grundy theorem?+

Every impartial game position has a Grundy number: G(P) = mex{G(P') : P' reachable}. The mex (minimum excludant) is the smallest non-negative integer not in the set. Game sums use XOR: G(G₁+G₂) = G₁⊕G₂.

What is nim-multiplication?+

Nim-multiplication (*) with XOR-addition forms a field. For powers of 2: 2^a * 2^b = 2^(a⊕b) if a,b have no common bit, else involves special Fermat 2-powers. Used in analyzing games like Turning Turtles and Wythoff's game.

Share this tool: