Intro to Nim

You are playing a game of Nim with a friend. There are n piles of stones. On each turn, a player chooses one pile and removes any positive number of stones from it. The player who takes the last stone wins. Both players play optimally. Determine whether the first player has a winning strategy.

Nim is the canonical impartial game and the reference point for most combinatorial game problems. Both players see the same piles and have the same options, every move removes stones, so the game always ends, and the player who takes the last stone wins.

The position is summarised by the nim-sum, the bitwise XOR of every pile size. A position with nim-sum zero is losing for the player to move, because any move changes exactly one pile and therefore makes the nim-sum non-zero. A position with non-zero nim-sum is winning: the player picks a pile whose highest set bit matches the highest set bit of the nim-sum and reduces that pile so the new nim-sum becomes zero. Repeating that reply hands a zero nim-sum back to the opponent on every turn. The answer therefore needs one pass over the piles to fold them together with XOR.

Examples
Input: [3,4,5]
Output: true
Hints

Intro to Nim

You are playing a game of Nim with a friend. There are `n` piles of stones. On each turn, a player chooses one pile and removes any positive number of stones from it. The player who takes the last stone wins. Both players play optimally. Determine whether the first player has a winning strategy.