1Write each pile in binary
Break every pile into place values of 16, 8, 4, 2 and 1. A pile of 5 is 4 + 1, so it’s 00101.
2Count the 1s in each column
If every column has an even number of 1s, the position is balanced. If any column is odd, it’s unbalanced. Writing a 1 under each odd column gives the nim-sum (programmers call it XOR).
3Always hand your opponent a balanced position
On your turn, take stones from one pile so that every column becomes even again. Keep doing that and you will take the last stone.
Your game right now
Example: piles of 3, 4 and 5
pile 3 = 0 1 1
pile 4 = 1 0 0
pile 5 = 1 0 1
1s = 2 1 2 ← the 2s column is odd: unbalanced
Fix it: change pile 3 (011) to 001 by taking 2 stones.
Now 1, 4, 5 = 001, 100, 101 → every column even.
Why it works
- The end is balanced. When no stones are left, every column has zero 1s, which is even. The player who just moved took the last stone and won.
- You can’t keep a balanced position balanced. A move changes only one pile, which flips at least one bit, so some column turns odd.
- You can always rebalance an unbalanced one. Find the leftmost odd column and pick a pile with a 1 there. Shrink that pile to (pile XOR nim-sum). That number is always smaller, so it’s a legal move.
- So the balancer wins. Whoever can keep handing over balanced positions makes the final move.
Why can you ever win? Who goes first alternates. If you start from a balanced position and the computer has to move first, it can’t fix it. Keep it balanced and the last stone is yours. You can also pick your own piles: try a balanced setup like 1, 2, 3 or 3, 5, 6.