The winner is the player who does not (or, as a variant, does) remove the last item.
Consider the setup of two piles of 2 items:
xx
xx
The player to move can be forced to lose by his opponent.
a) Last item loses:
-Remove one item and your opponent takes both items from the other pile;
- Take both items from one pile and your opponent removes just one from the other.
b) Last item wins:
Your opponent wins by mirroring your move.
Whether a particular start position is a guaranteed win (w/ best play) for the 1st of 2nd player is a function of whether the start position is a safe or unsafe one.
It is the positional sum in base 10 of the binary representation of the contents of each pile.
So
xxx
xx
x
has Nim sum of
11
10
01
---
22
This is a safe position as all final digits are even.
xxxxxxx
xxxxx
xxx
which has Nim Sum of
111
101
011
----
223
indicating an unsafe position.
First player can force a win by removing a single item from any row, to set the Nim sum as 222.
I know - I was said 8 or 9 year old.
Before internet Martin Gardner's "Mathematical Puzzles and Diversions" was the holy grail on the game.
amazon.ca/Scientific-Ame…
01101 = 13
10001 = 17
10111 = 23
11101 = 29
-------------
32314
This is an unsafe position - but despite the apparent complexity can be made safe in a single move, by removing 22 (ie 10110) items from either the 3rd pile.
01101 = 13
10001 = 17
00001 = 01
11101 = 29
-------------
22204
01101 = 13
10001 = 17
10111 = 23
01011 = 11 = 29-18
-------------
22224
01101 = 13
00111 = 07 = 17 - 10
10111 = 23
11101 = 29
-------------
22224
These latter two examples better illustrate the means by which **any** unsafe position can be rendered safe in a single move.
01101 = 13
10001 = 17
10111 = 23
00111 = 07 = 29 - 22
-------------
21324
01101 = 13
10001 = 17
10111 = 23
11101 = 29
-------------
32314
We have seen one of these already:
xx
xx
E.G.
xxx
xx
x
or
xxxxx
xxxx
x
x
x
x
x
are both safe but dangerous.