Misère Nim
Misère Nim is a variant of Nim where the player who takes the last stone loses. Determine if the first player has a winning strategy given optimal play from both sides.
Misere play flips the winning condition: the player forced to take the last stone loses. The usual nim-sum rule still decides the game while at least one pile holds two or more stones, because a player can always avoid being the one who empties the final pile.
The exception is the position where every pile holds exactly one stone. Then all moves are forced, and the player to move wins exactly when the number of piles is even. Combine the two rules by first checking whether any pile exceeds one stone. If one does, compare the XOR of all piles with zero. If every pile is a single stone, compare the pile count with parity instead. Both checks are linear passes and need no extra memory.
Misère Nim
Misère Nim is a variant of Nim where the player who takes the last stone **loses**. Determine if the first player has a winning strategy given optimal play from both sides.