In the 1901 paper that named the game Nim and provided its mathematical analysis, Charles Bouton defined “safe combinations”, positions that if you leave the game in this state, your opponent cannot win. In combinatorial game theory, these are
Bouton gives a list of “the 35 safe combinations all of whose piles are less than 16”, working in three-heap Nim. Naturally it seemed sensible to check these, so I wrote a bit of Python code to do this. Bouton’s list is good. I realised I could easily adapt my code to find out how many
And, having generated a sequence of integers, I naturally looked to see if it was in the OEIS. This is sometimes a good way to discover that your sequence of numbers is also found in some unexpected places. It wasn’t there! So I submitted it, and I just got the exciting email “N. J. A. Sloane published your changes”. So I present A363166: “Bouton numbers: a(n) is the number of P positions in games of Nim with three nonzero heaps each containing at most n sticks”.
This is my first OEIS submission, so it’s all very pleasing, even if I’m submitting a ‘new’ sequence inspired by a 1901 paper!
Just looking at the sequence up to n=256, and it appears that a(2^k)=a(2^k-1) for k in 1-8 (i.e. a(32)=a(31)=155). Is there any general reason why this should be true?
In fact, just scanning the list, the only n’s where a(n-1)=a(n) are when n is of the form 2^k
Hi Andy,
Good spot! Yes it’s entirely natural that this is the case.
Nim analysis is based on Nim sum – bitwise XOR addition of the binary representations of heap sizes. A position is one where the Nim sum is zero.
Now in the situation where we increase the maximum heap size to , we have three heaps that can now have a bit in a new binary place, the place. This heap size in binary will be since it can’t be larger than .
If one heap alone has sticks, the Nim sum cannot be zero because that 1 bit stands alone. In the case where all three heaps have sticks the Nim sum can’t be zero because the XOR addition of 1, 1 and 1 is 1 not 0. This leaves the case where two heaps are and the other is not – then, the two heaps that are will Nim sum to zero, meaning the overall Nim sum is equal to the size in binary of the third heap. This cannot be zero since we insist on nonzero heap sizes, so this cannot be a position either.
Therefore an increase to sticks as the maximum size can never produce more positions than the case.
Hope that made sense!
Thanks Peter, that is very nice.
I have found a formula for this sequence. Put where is maximal and . Then the number of P positions is
and so are in . We can choose any pair and then set the third number to their nim sum, which is necessarily shorter. . We choose any pair of numbers in the range together with their nim sum. Each P position will occur three times; hence we must divide the number of choices by 3.
which is
In any P position the largest two numbers must be the same length when written in binary, since the leading bits must xor to zero. The first term covers the case where the largest two numbers have the same length as
The second term covers the other case where all the numbers are shorter than
I think this method will generalise to more heaps.
This made me wonder about limiting the total number of sticks, rather than limiting each heap. Fix the total number of sticks to be exactly . Let be the Hamming weight of , that is, the number of 1-bits when is written in binary. When is odd the number of P positions is zero. When is even it is .