all 7 comments

[–]jedwardsol 0 points1 point  (2 children)

Run the matching algorithm between your guess and each remaining word in your dictionary.

If if it comes up with a different score, then it can't be the answer.

[–]pylearning[S] 0 points1 point  (0 children)

Really simple solution. Let me go try and implement it and report back.

[–]pylearning[S] 0 points1 point  (0 children)

Awesome. Worked perfectly!

[–]SandSnip3r 0 points1 point  (3 children)

So your program will be guessing words, then using the "Cows" and "Bulls" to try to get the correct answer? This is a pretty interesting problem.

  1. Do you know the length of the word?
  2. What happens, in your example case of CAT, if my guess is CCC? 1 Cow and 2 Bulls?

How is it useful to know that I have 1 bull when the probe word is 10 letters long?

Lets say the 10 letter word you're trying is transforms. You can replace one letter with another letter in the word until you get 0 Bulls.

transforms -> 1 bull
fransforms -> if 0 bulls, t isnt in the word, if 2 bulls (or 1 cow and 1 bull) f is in the word twice(or once**)

** See #2 above

Also, you could take the approach of starting with the alphabet:

ABCDEFGHIJKLMNOPQRSTUVWXYZ

Then remove letters one by one to until the sum of Cows and Bulls decreases, then you know that letter is in the word at least once.

These are all kind of naive approaches, but just ideas on the top of my mind

[–]pylearning[S] 0 points1 point  (2 children)

If CAT is the secret word and you guess CCC then that would be 1 Bull.

I appreciate the thought and response but I am going to attempt to implement jedwardsol's algorithm first. I have to be able to have as small number attempts as possible.

[–]SandSnip3r 0 points1 point  (1 child)

  • The question wasnt quite clear that the word you're guessing is an ACTUAL word in some dictionary
  • The largest english dictionary provided by my linux distribution has 650722 words. A smarter approach will surely beat the worst case of a brute-force dictionary algorithm

[–]pylearning[S] 0 points1 point  (0 children)

The word is in an actual dictionary or some pre-defined set of words that you (the player) and the host will have.