【Hacker Rank】Tower Breakers (solved within one line)



If there is one tower then Player 1 always wins by simply removing everything and leaveing just 1.
But if there are two towers then second player can always just copy the first player and therfore second player wins.
If there are three towers then first one wins by removing everything and leaving 1 and then just copying player two.
The only time that player one is going to lose if there is one tower which is it of height 1.
#!/bin/python3 import math import os import random import re import sys # # Complete the 'towerBreakers' function below. # # The function is expected to return an INTEGER. # The function accepts following parameters: # 1. INTEGER n # 2. INTEGER m # def towerBreakers(n, m): # Write your code here return 2 if n%2==0 or m==1 else 1 if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w') t = int(input().strip()) for t_itr in range(t): first_multiple_input = input().rstrip().split() n = int(first_multiple_input[0]) m = int(first_multiple_input[1]) result = towerBreakers(n, m) fptr.write(str(result) + '\n') fptr.close()

浙公网安备 33010602011771号