Created
March 13, 2023 08:58
-
-
Save samarthsewlani/ccb51aa809011b3f7937db6e2ad2626d to your computer and use it in GitHub Desktop.
Counter Game HackerRank Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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