public class TwentyQuestions
extends Object
Compilation: javac TwentyQuestions.java
Execution: java TwentyQuestions n
Dependencies StdIn.java
This code uses binary search to play the game of twenty questions.
It takes a command-line argument n, asks you to think of a number
between 0 and N-1, where N = 2^n, and always guesses the answer
with n questions.
% java TwentyQuestions 7
Think of an integer between 0 and 127
Is it less than 64? false
Is it less than 96? true
Is it less than 80? true
Is it less than 72? false
Is it less than 76? false
Is it less than 78? true
Is it less than 77? false
Your number is 77