Did you know, that if you write an application that guesses a number between 1 and 100, using an algorithm that always guesses on the number right between the max and the min numbers, letting the user input if the guess of too high or too low, it takes the program SEVEN tries to guess the number 77!!!
(Are you thinking of 50? // 1st guess
too low
Are you thinking of 75? // 2nd guess
too low
Are you thinking of 87? // 3rd guess
too high
Are you thinking of 81? // 4th guess
too high
Are you thinking of 78? // 5th guess
too high
Are you thinking of 76? // 6th guess
too low
Are you thinking of 77? // 7th guess!
yes
I got it right in 7 tries!
The code is:
too_low:
min = guess; // can't be less that this guess
guess = (max-min)/2 + min;
goto guess;
too_high:
max = guess; // can't be higher than this guess
guess = (max-min)/2 + min;
goto guess;