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
|
99 Discussions
|
Please Login in order to post a comment
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to give a star :) )
Go
Here's an explanation for some posted solutions.
In the edge case (m=1) Player 1 cannot move and Player 2 wins.
Now suppose (m > 1) and that we have an even number of towers (n % 2 == 0) . Player 1 can take some tower and reduce it to some divisor, which can be 1 or greater than 1. Player 2 can simply take another tower and match Player 1's move. Because there are an even number of towers, Player 2 will keep matching Player 1's moves until Player 1 can only reduce a tower to the divisor 1 (which Player 2 will match) and so Player 1 will be left with only towers of height 1, making Player 2 win.
If we have an odd number of towers (n % 2 == 1) Player 1 can reduce one tower to 1, meaning that Player 2 now has an even number of non-1 towers, and from before Player 2 must lose. Thus Player 1 wins.
Java:
Python 3