Tower Breakers

Sort by

recency

|

375 Discussions

|

  • + 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
    
  • + 0 comments

    js single line solution (also to make it a little more fun, chose to do it with no if statements):

    const towerBreakers = (n, m) => ((m==1)&&(2) || (2 - n%2));
    
  • + 0 comments

    I agree that the question, as is tradition on this site, is very poorly written and clearly not by someone that speaks english natively.

    The correct answer is not found in the Editorial, but is instead described pretty well on this SO answer.

    In short, 'optimal' does boil down to mirroring, because in the case that the next player does not mirror, the first can also avoid mirroring to force the same end result by bringing the invariant back into line with their victory. Look into nim games if that is not clear.

    The fact that this is ignored in the Editorial doesn't help the appearance of 'optimal' being an asinine definition of 'well just mirror because you can therefore its optimal'.

    Without knowing about nim games or just brute forcing a big truth table, this is not an easy question and is a pretty poor way to gauge understanding. Probably why it's tagged 'observation', they want you to just guess the correct answer based on simulating a few cases.

  • + 0 comments

    one thing i noticed that if number of towers i.e., n are even then player 2 will always win.