We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

- Tower Breakers
- Discussions

# Tower Breakers

# Tower Breakers

#### Sort by

recency

#### |

#### 330 Discussions

#### |

Please Login in order to post a comment

In each turn, a player can choose a tower of height x and reduce its height to y , where 1<=y

Very convoluted problem given the result. Like the solution, the prompt should be KISS (keep it simple, stupid).

This problem was kinda unsatisfying. At first i thought i needed to find how many divisors there are and find a way to get the best moves of each player at the end you can resume the player who wins depends on the number of towers:

It turns out that when you have an n

evennumber of towers either if the mheight is odd or eventhen you will end up always with an"Even number of moves"this results into player 1 not being able to win despite any strategy he decides to take. Since both players play the best move always.However it also turns out that when the number of towers is odd then in this case of m being even we end up with odd number of moves and in case of odd height in odd number of moves. Then P1 will always win.

There are two cases in case player 1 has no possible moves because towers height is 1 and when number of towers is 1 which in this case it is also necessary to control.

Sad problem.

this code test is ridiculous,don't try to solve it,it just waste of your time

every player can reduce height of a tower m to some divisor of m called y, inclusive of 1. if can't move, you lose. when can't move? only one left in all towers at your turn theoretically, optimal just means they remove as many units as possible so other player can't go --> basically always try to reduce to one

`def towerBreakers(n, m): if m == 1 or n % 2 == 0: # player 1 can't go at all # or player 1 can't go after player 2 match moves on another tower return 2 else: # more than 1 for height and last person to play is player 1 return 1`