You are viewing a single comment's thread. Return to all comments →
Java
public static String counterGame(long n) { final String LOUISE = "Louise"; final String RICHARD = "Richard"; boolean isLouiseTurn = true; int maxClosePower; long poweredNumber; long counter = n; if (counter == 1) { return RICHARD; } while (counter > 1) { maxClosePower = (int)(Math.log(counter) / Math.log(2)); poweredNumber = (long) Math.pow(2, maxClosePower); if (poweredNumber == counter) { counter /= 2; } else if (counter > poweredNumber) { counter -= poweredNumber; } isLouiseTurn = !isLouiseTurn; } return isLouiseTurn ? 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 →
Java