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
|
99 Discussions
|
Please Login in order to post a comment
if (m == 1) { return 2; } else { return ((n % 2) == 1) ? 1 : 2; }
Here is my explanation for the solution - pretty much the same as the discussion, but differently worded.
If m is 1 then there is no move the first player can make and they immediately lose, so 2nd player wins.
If any tower has a height greater than 1 then there is a move the player can take - reduce that tower to 1 - so the final state is always to have height 1 for all towers. This is what each player needs to aim for at the end of their turn.
If there is 1 tower of height m > 1 (with any number of other towers of height 1), then 1st player can reduce its height to 1, so 2nd player cannot move, so 1st player wins.
If there are 2 towers of height m > 1, then whatever reduction 1st player makes to one tower, 2nd player can make the same reduction to the other tower, keeping them equal. Eventually 1st player must reduce tower to 1, then 2nd player can reduce other two to 1, letting 2nd player win.
If there are 3 towers of height m > 1, then 1st player can reduce a tower to 1, leaving them in the situation of the 2nd player in the 2 tower case, so 1st player wins.
If there are an even number of towers of height m > 1, then 2nd player can match 1st player's move to maintain a situation where every tower has a paired tower of the same height, eventually the first player must reduce towers to 1, letting 2nd player win.
If there are an odd number of towers of height m > 1, then as with the 3 tower case, the 1st player can reduce a tower to 1, leaving them in the situation of the 2nd player in the even number of towers case, so 1st player wins.
Problem not clear, optimal choice is not clear enough to make an assumption what the player move is! bad description.. sorry
Java
Please define what optimal play is and don't leave it up to the coder. According to what I understood from the question, Player 1 can remove all blocks leaving one behind in let's say Tower A (one block evenly divides whatever initial number of blocks were present in A). And now Player 2 removes all but 1 block in tower B. So now Tower A and B are of height 1 and it is player 1's turn, he can't divide one block evenly -> so doesn't PLAYER 2 always win with this strategy?
Python3: