Professional Documents
Culture Documents
Steve Alpern's Overhead Slides Nim Games and Impartial Games
Steve Alpern's Overhead Slides Nim Games and Impartial Games
Steve Alpern's Overhead Slides Nim Games and Impartial Games
This file contains my overhead slides from the first two weeks of MA300/301/402.
In response to the requests of several students, I am putting them on the course
website. They are based closely on the course notes of Prof Von Stengel. These
slides are not really meant to be read on their own, but to be seen at the same
sime as my spoken commentary and my proofs or examples presented on the
visualizer. For reading at home, the course notes should be a better option.
The Game of Nim
• Nim(a,b,c) begins with ‘heaps’ sizes a,b,c
• Each player to move removes as many marbles
as he likes from any one pile
• Player I moves first, then II, then I, etc.
• The first player who cannot move (who faces all
empty heaps) loses.
• Either I or II has a winning strategy, for any
game Nim (a,b,c) (theorem, proof later)
• Nim(a,b,c) called ‘winning’ if I has win strat.
Examples
• Try Nim(1,2,3) with your neighbour.
• Try Nim(9,9)
• Try Nim (83,47)
Directed Graph Method to Solve Nim
2 1 1,1
2 1 1,1
1 0 0 1
0 0
Nim Sum
8 4 2 1
a 3 0 0 1 1
b 13 1 1 0 1
c 9 1 0 0 1
nim sum 7 0 1 1 1
To calculate nim sum, sum of a column of 0’s and 1’s is 0 if there are an
even number of 1’s, and sum is 1 if odd number of 1’s. In other words the
sum for each column is the sum modulo 2.
nim sum 7 0 1 1 1
10 1 0 1 0
a' 3 0 0 1 1
b' 10 1 0 1 0
c' 9 1 0 0 1
nim sum 0 0 0 0 0
Locate leftmost 1 in nim sum (in 4 column), take away from a row with a
1 in this column (second row). Change right part of this row to make sum 0
Winning & Losing Positions
• A position is winning if one of its options is
losing
• A position is losing is all of its options are
winning
• Recall the options of a position are the
positions you can leave it in after you
move
Winning unless nim sum zero
• Unbalanced positions have a balanced
option (two slides back)
• Balanced positions have only unbalanced
options (changing a single digit in a
balanced column unbalances it)
• So if you have an unbalanced position and
balance it, you will get back a balanced
position, and can never lose (the losing
position 0=0000 is balanced)
Winning and losing positions
• Unbalanced (nim sum not 0) winning
• Balanced (nim sum 0) losing, as any move
gives other player a winning position
Immediate losing
No out arrows, no
options
Immediate losing
No out arrows, no
options
Immediate losing
No out arrows, no
options
0
Nim(5,4) as directed graph
(5,4)
(0,0)
We denote a single heap Nim game by *n.
Lemma 1.2: In any Game G, either player I can force a win or II can.
*0 *0
*0
options 2 1 0
• Nim(1,0)==*1 3 1 1
• Nim(1,1)==*0
(copycat)
• Nim(2,0)==*2
• mex rule
• 3=mex{1,0,2}
Every I-Game == to Nim game
Proof. Use induction on game size. If true for all options, then true for
original game.