Tower Breakers

Sort by

recency

|

405 Discussions

|

  • + 0 comments

    Wow this problem was beyond bad. What a wierd question and such a poor explaination.

  • + 0 comments

    My Java 8 Solution

    public static int towerBreakers(int n, int m) {
            if (m == 1) {
                return 2;
            }
            
            if (n % 2 == 0) {
                return 2;
            } else {
                return 1;
            }
        }
    
  • + 0 comments

    Well, this was an 'interesting' problem. My 100% solution was a single line of code :-D

  • + 0 comments

    I agree, the question was worded wrong. My answer is wrong for contains the possibilities displayed by the instructions (taking into consideration floor levels)

            # Create towers
            tower_dic = {tower+1: [floor+1 for floor in range(m)] for tower in range(n)}
    
    winner = 2
    turn = cycle_1_2()
    
    # While we have towers (greater than 1 floor)
    while len(tower_dic) > 0:
    
        # If only one tower, make it 1 (remove from dic - end turn)
        if len(tower_dic) == 1:
            winner = next(turn)
            break
    
        # Elif odd number of towers, make last one 1(remove from dic - end turn)
        elif len(tower_dic) % 2 != 0:
            tower_dic.popitem()
            winner = next(turn)
            break
    
        # Else we have even number of towers
        else:
    
            # Try to make the other person get an even number too
            # For each tower
            for tower in tower_dic:
    
                # If even number of floors
                if len(tower_dic[tower]) % 2 == 0:
    
                    # turn into 2 floors (end turn)
                    tower_dic[tower] = [1,2]
                    winner = next(turn)
                    break
    
                # Else we odd number of floors
                else:
    
                    #Check if there are any divisible items besides from 1
                    for floor in tower_dic[tower]:
    
                        # If so, use that (end turn)
                        if floor > 8 and len(tower_dic[tower]) % floor == 0:
                            tower_dic[tower] = [i+1 for i in range(floor)]
                            winner = next(turn)
                            break
                        # Else move to next tower
    
            # Since there weren't any towers with number of floors with divisible numbers other tan 1
            # Turn first tower to 1 (remove from dic - end turn)
            tower_dic.popitem()
            winner = next(turn)
            break
    
    return winner
    
  • + 0 comments

    This is a horribly written question.