Scenario
In the combinatorial game of Nim, there are k piles of stones containing (s1,s2,…,sk) stones.
Two players alternate turns. On their turn, a player selects a single non-empty pile and removes any number of stones (at least 1, up to the entire pile).
Under normal play convention, the player who removes the last stone wins (the player with no moves loses).
Your Task
- Define the Nim-sum S=s1⊕s2⊕⋯⊕sk via bitwise XOR.
- State and prove Bouton's Theorem characterizing winning (N-positions) and losing positions (P-positions).
- Construct the winning move algorithm from any state with S=0.
- Solve the game starting with piles (3,4,5) by finding the unique winning first move.
Constraints
- Standard impartial game without chance or hidden information.
Examples
For (1,2,3), 1⊕2⊕3=0, so it is a second-player win (P-position). For (3,4,5), 3⊕4⊕5=2=0, so it is a first-player win (N-position).