Nim Game Basics

There are n piles of stones. Two players take turns removing any positive number of stones from a single pile. The player who takes the last stone wins. Determine if the first player has a winning strategy given both play optimally.

This is the standard normal play version of Nim, the version that gives the game its name. A move touches exactly one pile and reduces it, so the game is finite and draws are impossible.

The outcome depends only on the bitwise XOR of all pile sizes, called the nim-sum. Positions with nim-sum zero are losing for the side to move, because every legal move leaves a non-zero nim-sum, and every position with a non-zero nim-sum has a move that returns it to zero. To answer the question, fold the piles together with XOR and test whether the result differs from zero. The number of piles and the height of each pile influence the answer only through that single value.

Examples
Input: [4,8]
Output: true
Hints

Nim Game Basics

There are `n` piles of stones. Two players take turns removing any positive number of stones from a single pile. The player who takes the last stone wins. Determine if the first player has a winning strategy given both play optimally.