How to win any game on hackerrank

1 points by DhruvKumarJha ↗ HN
To win any game on hackerrank is very simple,

If you haven't played it, Play it first.

Step 1 : Choose a number "56"

Step 2 : You'll be asked to select/choose a number of candies between 1 and 5

Now, you goal should be, Whatever number you choose - total number of candies should be divisible by 6.

so, since n = 56

you answer = 56-?/6 = valid result.

If the number of candies you choose is 1, Then 56-1/6 = 55/6 => not a valid answer as it should be entirely divisible by 6 without any decimal points.

If no. of candies you choose is 2 then, 56-2/6 = 54/6 = 9 which is what we're looking for.

Forget whatever number computer chooses, Your goal should be always get the final number to be divisible by 6.

Sample challenge here.

challenge 23

Playing a game for N: 23

How many candies do you want to pick?: 5 (23-5/6 = 18/6 = 3)

Your move: '5'. Computer's move: '5'. Remaining candies: '13'

How many candies do you want to pick?: 1 (13-1/6 = 2)

Your move: '1'. Computer's move: '4'. Remaining candies: '8'

How many candies do you want to pick?: 2 (8-6/6 = 1)

Your move: '2'. Computer's move: '1'. Remaining candies: '5'

How many candies do you want to pick?: 5

Congrats! You won the game. Now go ahead and play for more candies. Enjoy :)

Let me know if you already knew this or if i screwed it up...

Screenshot of Another challenge : http://img542.imageshack.us/img542/6531/hackerrank.png

4 comments

[ 227 ms ] story [ 419 ms ] thread
posting 2129 requests takes approximately 25 hours with 200ms latency :) There is a better way :D
There was a better way. The code logic was exploited and I got myself 70 points more than the maximum expected .
What to do in case of multiple of 6... for eg if we take 6,12,18,24 etc ? It won't work then.