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.
Frankly speaking, after few attemtps to find solution, I gave up. But copy&pasting
the answer doesn't tune your mind to solve similar problems. Thus I've invested
my time into below explanation. I hope, it can help you as well.
Note how group of [2,4,8,16,15,13,9,1] is repeating over and over in intervals
of power 1-8, 9-16, 17-24, .. for . The same logic is for
What does it mean? For those cases when n is divisable by 8, the Second always
have one ore more options to counter-strike, i.e. to compensate any move done
by First.
This is so complex task and this solution is so clever.
Happy pythonong!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Powers Game
You are viewing a single comment's thread. Return to all comments →
Python3
TL;DR
What is behind this solution
Frankly speaking, after few attemtps to find solution, I gave up. But copy&pasting the answer doesn't tune your mind to solve similar problems. Thus I've invested my time into below explanation. I hope, it can help you as well.
ModuloThis task is about modulo mathematic, particualry:
( a + b) % c = ( ( a % c ) + ( b % c ) ) % c
( a * b) % c = ( ( a % c ) * ( b % c ) ) % c
( a – b) % c = ( ( a % c ) – ( b % c ) ) % c
( a / b ) % c NOT EQUAL ( ( a % c ) / ( b % c ) ) % c
In our case we transfer
( sign_1*2^1 + sign_2*2^2 + .. sign_n*2^n) % 17
into( (sign_1*2^1)%17 + (sign_2*2^2)%17 + .. +(sign_n*2^n)%17) % 17
Let have a look what will be modulo 17 for 2 in various power:
Note how group of [2,4,8,16,15,13,9,1] is repeating over and over in intervals of power 1-8, 9-16, 17-24, .. for . The same logic is for
What does it mean? For those cases when
n
is divisable by 8, theSecond
always have one ore more options tocounter-strike
, i.e. to compensate any move done byFirst
.This is so complex task and this solution is so clever.
Happy pythonong!