Skip to content

Instantly share code, notes, and snippets.

@samarthsewlani
Created March 13, 2023 08:58
Show Gist options
  • Save samarthsewlani/ccb51aa809011b3f7937db6e2ad2626d to your computer and use it in GitHub Desktop.
Save samarthsewlani/ccb51aa809011b3f7937db6e2ad2626d to your computer and use it in GitHub Desktop.
Counter Game HackerRank Solution
class Result {
public static String counterGame(long n) {
boolean flag = true;
while(n>1){
double power = logToBase(n, 2);
if( (n & n-1) == 0) n = n/2;
else{
n -= Math.pow(2, (int) power);
}
flag = !flag;
}
return flag ? "Richard" : "Louise";
}
public static double logToBase(long n, int b){
return Math.log(n) / Math.log(b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment