Skip to content

Instantly share code, notes, and snippets.

@joriki
Last active January 9, 2023 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joriki/007117204b8d8d2496d98f9fd9a6634d to your computer and use it in GitHub Desktop.
Save joriki/007117204b8d8d2496d98f9fd9a6634d to your computer and use it in GitHub Desktop.
Search the game tree of a repeat-a-number game; see https://math.stackexchange.com/questions/4605602
import java.util.BitSet;
public class Question4605602 {
static BitSet used = new BitSet();
public static void main(String [] args) {
System.out.println(value(1));
}
static boolean value(int move) {
if (used.get(move))
return true;
used.set(move);
boolean losing = value ((int) Math.floor(move / 3)) || value (2 * move + 1) || value (2 * move + 5);
used.clear(move);
return !losing;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment