Tower Breakers

  • + 0 comments

    Python 3

    return 2 if m ==1 else 1 if n % 2 else 2
    

    Explanation:

    1. if m (tower height) is 1, then Player 1 is unable to make a move, and lose the game. Player 2 is winner.
    2. For all other tower heights, the winner is determined by the number of towers n. Simulate 4 scenarious: with odd and even number of towers (1 and 2), with height 2, then 3, when each player makes it best (optimal) move.

    Happy pythoning!

    🦁