Sprague-Grundy Calculator

G(n) = mex of successors

CalculatorsFreeNo Signup
4.6(443 reviews)
All Tools

Loading tool...

About Sprague-Grundy Calculator

A Sprague-Grundy calculator computing Grundy values G(n) for impartial games. Uses the mex (minimum excludant) function: G(n) = mex({G(m) : m is a move from n}). Analyzes subtraction games, Euclid's game, and custom rulesets. Client-side.

Sprague-Grundy Calculator Features

  • Grundy values
  • Mex function
  • Subtraction games
  • Win/loss analysis
  • Game equivalence
Sprague-Grundy theorem: every impartial game position has a Grundy value G. G(n) = mex{G(m) : m reachable from n}. G=0 means losing (P-position). Game sum: G(A+B) = G(A) ⊕ G(B). Reduces any impartial game to Nim!

How to Use

Choose game type:

  • Subtraction: Remove from {s₁,...,sₖ}
  • Grundy values: Computed via mex
  • Win/Lose: G=0 or G>0

The Mex Function

mex(S) = minimum excludant = smallest non-negative integer NOT in S. mex({0,1,3})=2. mex({1,2})=0. mex({})=0. This builds Grundy values bottom-up from terminal positions.

The Theorem

Every position in an impartial game is equivalent to a Nim heap of size G(n). Sum of games: Grundy values XOR. So ANY impartial game can be analyzed using Nim theory!

Step-by-Step Instructions

  1. 1Choose game.
  2. 2Compute Grundy values.
  3. 3Find G(n).
  4. 4XOR for sums.
  5. 5Determine winner.

Sprague-Grundy Calculator — Frequently Asked Questions

What is an impartial game?+

A game where both players have the same moves available from any position. Nim, Wythoff, subtraction games are impartial. Chess is NOT (pieces have different moves for each player). For impartial games, Sprague-Grundy gives a complete solution.

How does the mex function work?+

mex({}) = 0 (terminal positions lose). mex({0}) = 1 (can move to a losing position, so we win). mex({0,1}) = 2. mex({0,2}) = 1. It's the smallest non-negative integer NOT achievable. This builds a complete game analysis.

What about partisan games?+

Sprague-Grundy only works for impartial games. Partisan games (like Chess, Go) use surreal numbers and Conway's theory from 'On Numbers and Games'. Much more complex!

Share this tool: