You are viewing a single comment's thread. Return to all comments →
this is the solution for java 8 the hardest work was to handle the execution time
public static String counterGame(long n) { double result = n; String winner = "Louise"; int repeat = 0; if (n != 1){ double base = Math.log(result) / Math.log(2.0); if (Math.floor(base) != Math.ceil(base)) { // double baseofn = Math.log(n) / Math.log(2.0); while (Math.floor(base) != Math.ceil(base)) { int baseint = (int) base; long lesspowoftwonumber = (long)Math.pow(2,baseint); n = n - lesspowoftwonumber ; base = Math.log(n) / Math.log(2.0); repeat++; System.out.println(repeat+" "+base+" "+n+" "+lesspowoftwonumber); } int baseint = (int) base+repeat; winner= (baseint%2 == 0)?"Richard":"Louise"; }else { int baseint = (int) base; winner= (baseint%2 == 0)?"Richard":"Louise"; } } else { winner = "Richard"; } return winner; }
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 →
this is the solution for java 8 the hardest work was to handle the execution time