Introduction
Nim is the basic model for impartial combinatorial games. There are several piles of stones. On each turn, a player chooses one non-empty pile and removes any positive number of stones. The player who cannot move loses.
The entire position is decided by one value: the bitwise xor of the pile sizes.
Problem or motivation
Given the current pile sizes, determine whether the first player can force a win. If a winning move exists, print one move as a pile index and its new size.
The game tree is enormous. Even a small increase in pile sizes creates many possible moves, so ordinary minimax is not useful.
Core concept
Let