You are viewing a single comment's thread. Return to all comments →
public static String counterGame(long n) { int counter = 0; while(n > 1) { int power =(int)(Math.log(n) / Math.log(2)); if(Math.pow(2,power) != n) n = n - (long)Math.pow(2,power); else n = n/2; counter++; } return (counter % 2 == 0) ? "Richard" : "Louise"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Counter game
You are viewing a single comment's thread. Return to all comments →
public static String counterGame(long n) { int counter = 0; while(n > 1) { int power =(int)(Math.log(n) / Math.log(2)); if(Math.pow(2,power) != n) n = n - (long)Math.pow(2,power); else n = n/2; counter++; } return (counter % 2 == 0) ? "Richard" : "Louise"; }