Categories

The (modified) NIM game

«The game here discussed has interested the writer on account of its seeming complexity, and its extremely simple and complete mathematical theory. The writer has not been able to discover much concerning its history, although certain forms of it seem to be played at a number of American colleges, and at some of the American fairs. It has been called Fali-Tan, but as it is not the Chinese game of that name, the name in the title is proposed.»

Thus wrote the mathematician Charles L. Bouton in Nim, A Game with a Complete Mathematical Theory (Annals of Mathematics, Vol. 3, No. 1/4 (1901 – 1902), pp. 35-39). Which does not help in understanding what NIM stands for at all. maybe New Interactive Media? Or Network Interface Module? Probably we will never know…

NIM is a time-killer strategy game that many of us played on our school desktops. How it works is best explained in this unsetting sequence from Last year in Marienbad by Alain Resnais:

The winning strategy to play the NIM game has been clearly explained in this video:

Notice that in the original NIM game only odd number of elements are present in each file, and that one can remove any set of remaining elements in that file.

The version of the game we are going to discuss differs in some important respects from NIM. The elements are bars written on a sheet of paper or blackboard (or your prison cell’s wall, for that matters).

1. The bars are crossed and not removed, and it is not permitted to cross one line twice. This means that this is not allowed: but this is 2. It is the one who crosses the last bar who wins.
3. We allow for files of both even and odd numbers of bars.

It turns out that this is a significantly different game from the original NIM, that we call mNIM for obvious reasons. In fact we don’t have an idea yet of how a winning strategy could work (if there exists one).

In one of our laboratories at Festivaletteratura, we used this simple game to construct a mechanical machine that performs a Machine Learning algorithm that learns to play this game at the second level (not much, we admit…). Something similar to MENACE, which learnt to play Tic-Tac-Toe. Each configuration of the game corresponds to a box, each move to the color of several beads contained in the boxes and, as the game is played over and over, the learning algorithm consists in adding or removing beads of certain colors from the boxes so that winning strategies are reinforced and losing strategies are penalized.

Some questions are: if we were to build a similar machine to learn to play a more advanced level of the game, how many boxes would we need? And how many colors and beads? And how many games should we play for the machine to learn effectively?

Let’s start with the first question. Let be number of boxes (configurations) if we only had one file of length , and be the number of boxes we will need to build the whole thing (configurations of the whole game).

The configurations of one bar are obviously two: Therefore .

The configurations of two bars are also easy to enumarate: Therefore .

Because we need five boxes to represent the configurations of the second row per each configuration of the first row, the overall number of boxes needed to construct the machine is How many configurations and boxes are needed for the 3rd level of the mNIM game?

I’m sure you just brilliantly solved this problem, so let’s move on. How many boxes do we need to construct if we want to play mNIM in the 5th level?     Of course, it should be clear that You know from the previous exercise, but what about and ? You will soon realize that finding a direct answer by counting all of the configurations is a bit crazy. We need some clever trick to compute all possible single-file combinations in a general way, making sure that we do not leave anything behind…

Is there a guiding principle? Well, we could just inspect the easier cases and that we have under our noses. One general idea is that, if we want to go to , we could just look at regularities in moving from . This kind of principle is called proof by induction.

For , notice that we can group all cases into three subcases: the two where the last is not crossed the ones were it is crossed on its own and the one where it is crossed together with its neighbour: Can you do a similar separation for the case of bars that you worked out before? What does it look like? Is there any hint of a similarity with the previous case?

What about bars? Suppose we know the number of configurations of fewer bars , and that we add one more bar: We want to express the number of configurations in terms of the number of configurations of fewer bars.

Definitely, when the last bar is not crossed each configuration of the previous bars contributes. Therefore we have at least Same is true when the last bar is checked on its own: Therefore we have at least: But it can also be the case that the last bar is checked together with its nearest neighbour: In this case, we have as many configurations as there are configurations of the previous bars. Therefore we have at least: But the last line could also be crossed together with its second nearest neighbour, or its third nearest neighbour, or its -th nearest neighbour up to : You can probably see where this is heading to. We can condense the final formula as follows: So, if we know all of the previous up to , we can obtain the -th. Yet another way to write it is which will be familiar to most mathematicians.

Prove this formula!

Let’s test our formula against the configurations we already know! First we try out . Our formula says that But wait! How many configurations are there of the mNIM game with zero bars? This is a very weird question! What does it even mean to play the mNIM game if we have no bars at all?

However, somehow, with a little stretch of imagination mathematics allows to give an answer to this question that is compatible with the problem we need to solve, even if we don’t have an intuition of whatever it means to play the mNIM game with zero bars! Since we already know that , it must be that Let’s now check our formula further on. We have that  It works!

So finally we are in place to predict how many boxes we need to fill to instruct our machine-learning machine to play the 5-th level of the mNIM game. Let us remember that The only ingredient we missed were and , but now we have them! Thanks to our formula we obtain  and finally Quite a big number already! But how large is this number growing? That’s the question we want to answer next.

Let us take a closer look at the sequence that we obtained: Does it remind you of something? Well, let us fill in some other numbers (ours are in bold): Does this sequence ring a bell? If it doesn’t, you may just plug in the first few numbers in the Online Encyclopedia of Integer Sequences.

Well, it looks like are the odd terms in the Fibonacci sequence! But are we sure of this? What if after a while the pattern changes? Let us prove this fact. The Fibonacci sequence is defined by We want to express this just in terms of etc.:   and so on until you hit the bottom. After a little thought you will realize that we obtain precisely the generating sequence for that we said above would be familiar to most mathematicians. Now it’s familiar to you as well!

Now we can estimate how fast grows. In fact we know that for large  where is the golden ratio. But then because is smaller than one for large , then grows like This is all the more interesting if considering that the Fibonacci sequence is obviously related to the numbering of Scienceground episodes, the first being 1, the second 2, the third 1.5 and, as already announced, the fourth will be 1.6666666…..

As regards , we have that So basically the number of boxes grows with the golden section elevated to the square of the number of the level. So for example, if each person in the world has, let’s say, 10 boxes, and we could collect all of them (which makes 75 billion boxes), to which level could we program our machine?

Answer: just 6! And it does not change if one everyone had 100 boxes!

What about the original NIM game? How many boxes should we build for it?

This site uses Akismet to reduce spam. Learn how your comment data is processed.