Nim - Single Pile

Last updated January 13, 2024

The name Nim comes from the old English, or German, for ‘to take away’.  There are many varieties of Nim type games, and some have a nice mathematical strategy.

Rules

  • In the Single Pile version, you start with a pile of stones, marbles, matches, counters, . . . or just a number written on a piece of paper!
  • I shall start with 15 marbles.
  • The players take turns to remove 1, 2 or 3 marbles from the pile on each turn.
  • Whoever takes the last marbles loses!

The game appeared in several early adventure games on personal computers in the 1980’s as a challenge to overcome before progressing in the adventure.

My favourite implementation is Dr. Nim – a plastic, Nim playing automaton!

Once set up, Dr. Nim plays the perfect game!  I used it with school students, and I must admit to enjoying the eager volunteers being humbled in front of a class by a plastic computer!  Dr. Nim became unavailable but was relaunched as Braino.  However, I just looked on the web, and it is no longer available to buy new from  Maths Gear or anywhere else.  Sold out!

Strategy

  • 12 year olds have no problem picking up the winning strategy by repeatedly playing!
  • It soon becomes apparent that leaving 5 marbles wins.
    If your opponent takes 1/2/3 then you take 3/2/1 leaving 1 in each case.
  • I was always surprised that children found it harder to find the next step.
    Leaving 9 is also wins strategy, using the same 3/2/1/ idea to force 4 being taken in total.
  • Repeating this concept, leaving 13 wins, so taking 2 for the first player wins.
  • If you play second against an opponent who does not know the winning strategy, but happens to take 2 on the first go, muddy the water and hope – probably by taking only 1 which leaves the maximum scope for error.

Variations

  • The player who takes the last marble wins.  Here, it is easier to spot that multiples of 4 are the key, winning by leaving  4, 8, 12.
  • Start with a different number of marbles.
  • Allow a different maximum number of marbles to be taken each turn.
  • Any combination of the above!
  • Player A chooses the size of the pile; Player B chooses how many max per turn; Player A chooses who goes first (or any combination of these).

Mathematics

  • With my original game, leaving 4n+1 marbles wins.
    I have used this formula with children who have no experience of algebra!  I just explain that n means any number so just ‘4 lots of that number plus 1’, i.e. 5, 9, 13, . . .
  • With a max of m per turn, we need to leave  n(m+1) + 1
  • If picking up the last marble wins, then use n(m+1)

Here is a link to a Matt Parker YouTube video about Dr. Nim (he uses one of the variations to my main game)  The Unbeatable Game from the 60s: Dr NIM