

How to win any game on hackerrank - DhruvKumarJha

To win any game on hackerrank is very simple,<p>If you haven't played it, Play it first.<p>Step 1 : Choose a number "56"<p>Step 2 : You'll be asked to select/choose a number of candies between 1 and 5<p>Now, you goal should be, Whatever number you choose - total number of candies should be divisible by 6.<p>so, since n = 56<p>you answer = 56-?/6 = valid result.<p>If the number of candies you choose is 1, Then 56-1/6 = 55/6 =&#62; not a valid answer as it should be entirely divisible by 6 without any decimal points.<p>If no. of candies you choose is 2 then, 56-2/6 = 54/6 = 9 which is what we're looking for.<p>Forget whatever number computer chooses, Your goal should be always get the final number to be divisible by 6.<p>Sample challenge here.<p>challenge 23<p>Playing a game for N: 23<p>How many candies do you want to pick?: 5 (23-5/6  = 18/6 = 3)<p>Your move: '5'. Computer's move: '5'. Remaining candies: '13'<p>How many candies do you want to pick?: 1 (13-1/6 = 2)<p>Your move: '1'. Computer's move: '4'. Remaining candies: '8'<p>How many candies do you want to pick?: 2 (8-6/6 = 1)<p>Your move: '2'. Computer's move: '1'. Remaining candies: '5'<p>How many candies do you want to pick?: 5<p>Congrats! You won the game. Now go ahead and play for more candies. Enjoy :)<p>Let me know if you already knew this or if i screwed it up...<p>Screenshot of Another challenge : http://img542.imageshack.us/img542/6531/hackerrank.png
======
elssar
Kinda like the 21 game where the winning strategy is to always say a multiple
of 4(and it helps if you go second)
<http://en.wikipedia.org/wiki/Nim#The_21_game>

------
JagHacker
What to do in case of multiple of 6... for eg if we take 6,12,18,24 etc ? It
won't work then.

------
sairamkunala
posting 2129 requests takes approximately 25 hours with 200ms latency :) There
is a better way :D

~~~
sairamkunala
There was a better way. The code logic was exploited and I got myself 70
points more than the maximum expected .

