Two players are playing a game of Tower Breakers! Player always moves first, and both players always play optimally.The rules of the game are as follows:
Given the values of and , determine which player will win. If the first player wins, return . Otherwise, return .
There are towers, each units tall. Player has a choice of two moves:
- remove pieces from a tower to leave as
- remove pieces to leave
Let Player remove . Now the towers are and units tall.
Player matches the move. Now the towers are both units tall.
Now Player has only one move.
Player removes pieces leaving . Towers are and units tall.
Player matches again. Towers are both unit tall.
Player has no move and loses. Return .
Complete the towerBreakers function in the editor below.
towerBreakers has the following paramter(s):
The first line contains a single integer , the number of test cases.
Each of the next lines describes a test case in the form of space-separated integers, and .
2 t = 2
2 2 n = 2, m = 2
1 4 n = 1, m = 4
We'll refer to player as and player as
In the first test case, chooses one of the two towers and reduces it to . Then reduces the remaining tower to a height of . As both towers now have height , cannot make a move so is the winner.
In the second test case, there is only one tower of height . can reduce it to a height of either or . chooses as both players always choose optimally. Because has no possible move, wins.