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
|
383 Discussions
|
Please Login in order to post a comment
My answer with Typescript.
Firsts & second attemp i was try to calculate every tower / every move can do. correct but take too many time.
Thirt attemp, I realized every player will reduce tower to 1 when they can, so i just need to know numbers of tower that divide to 2 tp know the winner, a exception is the tower already height 1, so whatever numbers of tower, player move firsts will lose, the winner is 2.
public static int towerBreakers(int n, int m) { // Write your code here int result=0; if(m==1){ result=2; }else{ if(n==1){ result=1; }else{ if(n%2==0){ result=2; }else{ result=1; } } } return result;
The fact that every tower can be reduced to 1 since the 1st move makes that tower not choosable again. So then, if the height of towers is 1 since the beggining makes P2 to win by default as P1 cannot reduce any tower and he goes first. if the number of towers is pair then P2 will win as P1 will reduce one of them to 1 and in the next turn P2 will do the same, then no more chances for P1. If the number of towers is odd, then P1 will win as he will have the last turn.
I don't understand the meaning of evenly in this problem. If evenly means there is not any remainder from the division, why are 1 and 3 the only y values mentioned in the example (and not 2)?
I made this out to be harder in my head than it needed to be.