Sort 110 Discussions, By:
Please Login in order to post a comment
More of an English challenge than a coding challenge.
Even though I got the answer and the underlying logic, I still think this is actually a very tough problem. I say so because of the following reasons:
You have to first understand the complicated game and its rules properly (slightly challenging)
You then have to find the correct way to win this game from the perspective of each player (extremely challenging)
So basically, there are two cases here. Both cases rely heavily on the idea that an even number of towers (say 2n) can be thought of as a collection of n pairs of towers.
CASE 1) If there are an even number of towers
Player 1 will go first, and Player 2 will basically copy player 1. Whatever player 1 does to a tower, player 2 will do the exact same thing to the other tower belonging to the same pair. In this case Player 2 will always win.
CASE 2) If there are an odd number of towers
Player 1 will go first, and simply destroy any single tower by setting it equal to 1. Now we again have the same situation from CASE 1 but this time the roles of both players have been reversed. In this case Player 1 will always win.
Finally, there is also the trivial case where n does not matter because m = 1. In this case Player 2 will obviously always win.
This difficulty is suposed to be EASY.
Typo: "Player 1 removes 2 pieces leaving 1. Towers are 1 and 2 units tall."
Should read: "Player 1 removes 2 pieces leaving 1. Towers are 1 and 3 units tall."
This made me crazy, I kept tyring to figure out what I was missing.
How is taking 5 and leaving 1 evenly divisible? Is the problem saying your options are to reduce the tower by making an equally divsible group OR reducing the tower down to 1?
In the example given can't player 1 also take four blocks leaving two? As 6%2 = 0?