On Feb 14, 1:43 pm, "ramu" <ramu....@[EMAIL PROTECTED]
> wrote:
> Hi,
> can anyone give me the algorithm for cows and bulls game which takes
> minimum number of p***** to guess a 4-digit number?
>
> regards
I can give you the algorithm that takes the minimum number of p*****
to guess any number in a given range.
GUESS_NUMBER(MAX, NUMBER)
MIN = 0
GUESS = (MAX - MIN) / 2 + MIN
WHILE GUESS != NUMBER
IF GUESS > NUMBER
MIN = GUESS
ELSE IF GUESS < NUMBER
MAX = GUESS
Where MAX is the highest number, so in your case 9999, and NUMBER is
the number you're trying to guess.
Hope this helps!


|