The Game of Nim.

Last updated: 30 June 2024: David Green

1. Background

Amongst the Woodger papers in the Wroughton Archives is a flowchart (below) for NIM on Pilot Ace. Called NIM 2, there is no date and no author's name. The code pre-dates November 1951 because it uses TS8 and TS9 instead of DL's 8 and 9. It possibly dates to before Pilot Ace was built and there is no evidence a version ever ran on Pilot Ace.

Case

NIM is a game in which two players take turns in removing objects from discrete piles. Each player in turn must remove at least one object, and may remove more than one of the objects, but all the objects must be from the same pile. Sometimes the goal is to be the last player to take an object; sometimes (misère game) it is to force your opponent to take the last object.

The game is thought to be very old. Its current name was coined by Charles Bouton who developed the theory of the game in 1901. The theory uses the binary "exclusive or", written here as ⊕, to calculate "nim-sums". The winning strategy is to ensure that the nim-sum of the piles is zero when you complete your move. This is always possible if the nim-sum is not zero before your move.

For example, faced with three piles (A, B, C) of 3, 4 and 5 objects, your first step would be:

The full game might proceed as follows:

Wikipedia has a substantial article about NIM.

2. NIM 3

NIM 2 had the limited objective of finding a winning move for a given set of piles or advising that no such move was available. Playing with physical piles outside the computer, the operator would have to adjust for the recommended move or deal with the losing situation, observe his opponent's move, then feed the new pile sizes into the computer for more advice.

I think it is clear that NIM 2 was not meant to be a demonstration program - few lay persons are familiar with binary numbers and hardly anybody with the backwards binary it uses.

In fact the Pilot Ace has ample capacity to play a full game against an operator, as witness NIM 3. I wrote this version of NIM in 2016, based on NIM 2. Program cards suitable to play the game on the emulator can be downloaded here and a flow chart of the program is shown at the end of this page.

The object of NIM 3 is to be the last player to take a piece. Some notes:

To play the game:

Example: in the case mentioned above where there are three piles (A, B, C) containing 3, 4 and 5 objects and the operator wants the computer to move first, the game would progress as follows (ss is single shot, i.e. press the "ONE SHOT" switch once):

3. Flow Chart of NIM 3

NIM3 FlowChart 1

NIM3 FlowChart 2

NIM3 FlowChart 3

©2010-2024 David Richard Green. All rights reserved.
dgreen@uraone.com