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.
- Prepare
- Algorithms
- Game Theory
- Tower Breakers
- Discussions
Tower Breakers
Tower Breakers
Sort by
recency
|
102 Discussions
|
Please Login in order to post a comment
The way I see it, the second test case is wrong. 1 tower of 7 pieces. If players do the optimal play, the game would go like this:
Same with the second one. 3 tower of 7 pieces. Player 2 forces P1 to take the first piece from each tower and Player 2 will win.
The example they use for explaination breaks their game's rule. y%x=0. When you have 2 towers of height 3. You have no moves left to make as you can't make 2 divisible by 3. 2%3 =2; The example says this move is valid. Removing 5 from a tower of height 6 is also not an option as 5%6 =5;
I understand the trick is to find the pattern, but giving a bad example leads to confusion.
function towerBreakers(n, m) { return m===1 || n%2 === 0 ? 2 : 1; }
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to give a star :) )
Go