by "Geoffrey Summerhayes" <sumrnot@[EMAIL PROTECTED]
>
Feb 14, 2007 at 12:47 PM
On Feb 13, 10:43 pm, "ramu" <ramu....@[EMAIL PROTECTED]
> wrote:
> Hi,
> can anyone give me the algorithm for cows and bulls game which takes
> minimum number of passes to guess a 4-digit number?
>
This isn't optimal but does almost as well.
Each turn:
Get the list of all possibles remaining.
clear container for candidate move
For x from list.start to list.finish
zero out score counts
For y from list.start to list.finish
calculate score for list[x] if answer is list[y]
count[score]++;
end for
if the max in count is less than the current candidate's
set x as the new candidate
end if
end for
return candidate
Basically it looks for a guess that will minimize
the number of remaining possibles whatever the
results of the guess are.
The optimal strategy sometimes makes a guess that
can not be a solution and sometimes leaves larger
than minimum possibles behind. Classic paper on
the subject was by Knuth on mastermind.
---
Geoff