Tower Breakers

Sort by

recency

|

117 Discussions

|

  • + 0 comments
            // Write your code here
            /*
                If m == 1, the towers are all of height 1
                -> No moves possible
                -> Player 1 loses, so return 2
    
                If n is even, whatever move Player 1 makes,
                -> Player 2 can mirror it on another tower
                -> Player 2 wins -> return 2
    
                If n is odd and m > 1,
                -> Player 1 can always win
                -> return 1
            */
            if(m == 1 || n%2 == 0)
            {
                return 2 ;
            }else{
                return 1 ;
            }
        }
    
  • + 0 comments

    Alright, I cannot even figure out from the description what an "optimal" move is! And is it required that the reduction of a tower divides into the remaining height of the tower evenly or what? I'm not very happy wasting so much time just to figure out what a games rules are.

  • + 0 comments

    My Javascript solution

    function towerBreakers(n, m) {
        // Write your code here
        return (m === 1 || n%2 === 0) ? 2 : 1
    }
    
  • + 0 comments

    If you are here because the discription doesn't match the results, you gotta consider that a tower can be reduced directly to 1. example:

    2 towers of height 7

    p1: 7 -> 1 (x=1 y=6 -> x divides y)

    p2: 7 -> 1 (x=1 y=6 -> x divides y)

    p1 loses

    p2 wins, therefore returns p2

    the description says that y should divide x but in reality x should divide y

  • + 0 comments

    Please fix that description