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.
At first I had tried to modulos N by 10 (n = n%10) and set the number of if statements for each possibility from 1 to 10 to determine the winner, I was completely wrong. So I purchased the Test Cases for TC #0 and noticed that the pattern repeated itself after the 7th entry, it would go "Second First First First First First Second" and after that the pattern was the same. So I realized the best answer was to check if n was equal or greater than 7 and if so modulus n by 7 (n = n % 7). If the remainder was 0, it meant n was equal to the 7th case of the pattern (7 or 14 for example) and Player 2 Wins or if the reminder was 1, it meant n was equal to the 1st case of the pattern (8 or 15 for example) and Player 2 wins, any other remainder meant Player 1 wins.
Game of Stones
You are viewing a single comment's thread. Return to all comments →
C++ Solution and Explaination:
At first I had tried to modulos N by 10 (n = n%10) and set the number of if statements for each possibility from 1 to 10 to determine the winner, I was completely wrong. So I purchased the Test Cases for TC #0 and noticed that the pattern repeated itself after the 7th entry, it would go "Second First First First First First Second" and after that the pattern was the same. So I realized the best answer was to check if n was equal or greater than 7 and if so modulus n by 7 (n = n % 7). If the remainder was 0, it meant n was equal to the 7th case of the pattern (7 or 14 for example) and Player 2 Wins or if the reminder was 1, it meant n was equal to the 1st case of the pattern (8 or 15 for example) and Player 2 wins, any other remainder meant Player 1 wins.