Tower Breakers

Sort by

recency

|

378 Discussions

|

  • + 0 comments

    i never play a game in whole my life

  • + 0 comments

    The question is testing your ability to understand a game...

  • + 1 comment

    I had to spend WAY more time thinking about the logic of the game itself than the coding, which makes me question the validity of this as a coding exercise as opposed to an exercise in logic.

  • + 0 comments

    Can someone tell me if this is an error in the description or not?

    "Player 2 matches the move. Now the towers are both 3 units tall.

    Now Player 1 has only one move.

    Player 1 removes 2 pieces leaving 1. Towers are 1 and 2 units tall. "

    If there is no error in here, why after the move of Player 1, the towers are 1 and 2 units tall instead of 1 and 3?

  • + 1 comment

    This can be solved quite simply following this logic.

    If n is even, player 2 will create pairs of towers, such that whenever player 1 moves, they make the same move on the towers pair. Since the number of towers is even, this will always result in them winning.

    Alternatively, in n is odd, then player 2 only wins if the height of the tower is 1

    def towerBreakers(n, m):
        # Write your code here
        return 2 if (n % 2 == 0 or m == 1) else 1