tiles lie on a table. Anna and Boris take turns removing exactly one tile, Anna first.
Keep track of the bitwise XOR of the numbers still on the table (the XOR of a single tile is its number, and the XOR of an empty table is 0):
- if the XOR of the remaining tiles is 0 at the start of a player's turn, that player wins at once;
- if a player's move makes the XOR of the remaining tiles equal to 0, that player loses.
Both play optimally. Return True if Anna wins and False otherwise.tiles=[4, 4, 6] → False
If Anna removes 6, [4, 4] is left with XOR 0 and she has lost. If she removes a 4, [4, 6] is left with XOR 2; Boris removes either tile, and Anna has to remove the last one, bringing the XOR to 0. Anna loses.
tiles=[5, 9] → True
Whichever tile Anna removes, Boris is left with one nonzero tile, and removing it brings the XOR to 0. Anna wins.
tiles=[3, 5, 6] → True
3 XOR 5 XOR 6 = 0 before any move, so Anna wins straight away.
tiles=[4, 4, 6]
False
Run checks the first 3 tests in your browser. Submit checks all 119 tests on the server, hidden ones included.