// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class NumGuess {
    public static int find(int min, int max, int n) {
        int count = 0;
        int min2 = min;
        int max2 = max;
        int guess;
        for(;;) {
            count++;
            guess = (min2 + max2 + 1) / 2;
            if(guess == n) {
                break;
            } else if(guess < n) {
                min2 = guess + 1;
            } else if(guess > n) {
                max2 = guess - 1;
            }
        }
        return count;
    }
    public static void main(String[] args) {
        int sum = 0;
        for(int i = 1; i <= 1000; i++) {
            int guesses = find(1, 1000, i);
            sum += guesses;
            System.out.println(i + " " + guesses);
        }
        System.out.println(sum/1000.0);
    }
}
