/-/S'pht-Translator-Active/-/


Another magic thing about the number SEVEN!
Posted By: Vid BoiDate: 2/22/02 6:10 a.m.

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;

[ | Message Index | Read Prev Msg | Read Next Msg ]
Pre-2004 Posts

Replies:

Another magic thing about the number SEVEN!Vid Boi 2/22/02 6:10 a.m.
     Re: Another magic thing about the number SEVEN!M-Class 2/23/02 3:58 p.m.



Problems? Suggestions? Comments? Email maintainer@bungie.org

Marathon's Story Forum is maintained with WebBBS 5.12.