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
- 1Enter heap sizes.
- 2Compute nim-sum.
- 3Check position.
- 4Find winning moves.
- 5Play optimally.