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.
I didn't think about it inductively (formally), although that is definitely a great way to think about it.
Another way is to test it out yourself until you see a pattern. You know that 2-6 will leave P1 as the winner, and you know that 7 will leave P1 as the loser. With this in mind:
Begin walking up one by one, deciding who would win given an input. 8 would leave P2 as the winner because P1 would subtract [2,3,5], leaving P2 with [3,5,6], all in the winning section.
Knowing that being at 7 or 8 cause that player to loose, figure out how the other player (P1) can 'force' P2 to get to 7 or 8 (Since P1 starts, she has the upper hand). You'll get to the point where you see that the next loosing numbers to be at are [14,15] which happen to be n%7[0,1] (As seen by the induction above). Hopefully then you will catch the pattern :)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Game of Stones
You are viewing a single comment's thread. Return to all comments →
I didn't think about it inductively (formally), although that is definitely a great way to think about it.
Another way is to test it out yourself until you see a pattern. You know that 2-6 will leave P1 as the winner, and you know that 7 will leave P1 as the loser. With this in mind:
Begin walking up one by one, deciding who would win given an input. 8 would leave P2 as the winner because P1 would subtract [2,3,5], leaving P2 with [3,5,6], all in the winning section.
Knowing that being at 7 or 8 cause that player to loose, figure out how the other player (P1) can 'force' P2 to get to 7 or 8 (Since P1 starts, she has the upper hand). You'll get to the point where you see that the next loosing numbers to be at are [14,15] which happen to be n%7[0,1] (As seen by the induction above). Hopefully then you will catch the pattern :)