# Alice and bob xor nim game

Alice and Bob are playing a game. The rules of this game are as follows:

• Initially, there are $N$ piles of stones, numbered $1$ through $N$. The i-th pile contains $A[i]$ stones.

• The players take alternate turns. If the bitwise XOR of all piles equals 0 before a player's turn, then that player wins the game.

• In his/her turn, a player must choose one of the remaining piles and remove it. (Note that if there are no piles, that player already won.)

We need to decide which player wins, given that both play optimally and Alice starts the game.

Example : Let $N=4$ and stones in piles are : $[1,2,4,8]$ in this Alice will win. But if $N=3$ and stones in piles are : $[2,3,3]$ then Bob is going to win.

• Do Not Answer. Live Contest. hackerrank.com/contests/codesprint4/challenges/stonegame Mar 21, 2016 at 6:55
• @Dhruv The site says that Code Sprint 4 has ended, it was running in February. Mar 21, 2016 at 9:44
• @Dhruv: That's also a different question. Mar 21, 2016 at 19:23