OFFSET
1,5
COMMENTS
In combinatorial game theory, if the next player cannot win (assuming perfect play) we call this a P position.
Bouton (1901) called P positions in Nim "safe combinations" and provided a list of 35 such positions in games with less than 16 sticks in each heap. Bouton excluded positions where any heap has been reduced to zero sticks. This seems reasonable since if a pile is removed the game is reduced to a two-heap Nim game, so we follow Bouton here.
These positions have Nim sum zero. Nim sum is calculated by converting the heap sizes to binary and applying bitwise XOR addition.
The paper cited named the game Nim and provided the first known mathematical analysis.
LINKS
Peter Rowlett, Table of n, a(n) for n = 1..256
C. L. Bouton, Nim, A Game with a Complete Mathematical Theory, Annals of Mathematics, 3 (1901), 35-39.
EXAMPLE
With n=1, there is one stick in each pile. This is an N position (the next player can force a win) since the next player can take any stick and 0 1 1 is a P position, so a(1)=0.
With n=3, the only P position is 1 2 3, so a(3)=1. This is the simplest P position in three-heap Nim in that it uses the least number of sticks overall.
Bouton's list is a(15)=35: 1 2 3, 1 4 5, 1 6 7, 1 8 9, 1 10 11, 1 12 13, 1 14 15, 2 4 6, 2 5 7, 2 8 10, 2 9 11, 2 12 14, 2 13 15, 3 4 7, 3 5 6, 3 8 11, 3 9 10, 3 12 15, 3 13 14, 4 8 12, 4 9 13, 4 10 14, 4 11 15, 5 8 13, 5 9 12, 5 10 15, 5 11 14, 6 8 14, 6 9 15, 6 10 12, 6 11 13, 7 8 15, 7 9 14, 7 10 13, 7 11 12.
PROG
(Python)
from itertools import combinations_with_replacement
for n in range(1, 16):
num_digits = len('{0:b}'.format(n))
count=0
comb = combinations_with_replacement(['{0:b}'.format(i).zfill(num_digits) for i in range(1, n+1)], 3)
for heaps in comb:
heapsums = [0 for i in range(0, num_digits)]
for heap in heaps:
for d in range(0, num_digits):
heapsums[d] += int(heap[d])
if not True in (heapsum % 2 != 0 for heapsum in heapsums):
count +=1
print(n, count)
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Peter Rowlett, Jul 06 2023
STATUS
approved