There is no way to “always get it in one guess” in Bulls and Cows (called Hit & Blow in Japan), because on the first guess you have no clues at all. But there is a way to ”solve any answer within a fixed number of guesses.” If we call that a winning strategy, how many guesses are always enough?

Here we used the same rules as the app “Bulls and Cows” (10 symbols, 0 to 9, and both the answer and the guesses use all-different symbols), and calculated how many guesses each strategy needs for every 3-digit and 4-digit answer. A guess that is right counts as one guess.

Three strategies

  • Strategy A (fitting rows, in order): Guess the first row, in numerical order, that does not contradict the clues so far. It is close to how a person plays on paper.
  • Strategy B (make the worst case small): For each guess, split the answer candidates by the possible clues and guess the row that makes the biggest leftover group smallest.
  • Strategy C (make the average small): For each guess, guess the row that makes the average number of leftover candidates (the sum of the squares of the group sizes) smallest.

Strategies B and C also use rows that contradict the clues. Even a row you know is wrong can pay off if it splits the candidates well. The 1st guess is the same whichever you pick, so we start with “012” for 3 digits and “0123” for 4 digits (because every row has the same shape once you swap symbols and places).

Results for 3 digits (all 720 answers)

StrategyAverageWorst case
A Fitting rows, in orderabout 5.279
B Make the worst case smallabout 5.126
C Make the average smallabout 5.076

With strategies B and C, any answer can be solved in 6 guesses or fewer. Even with strategy A, the average is about 5.3, but an unlucky answer can take 9.

Results for 4 digits (all 5040 answers)

StrategyAverageWorst case
A Fitting rows, in orderabout 5.569
B Make the worst case smallabout 5.347
C Make the average smallabout 5.277

With 4 digits, strategies B and C solved any answer in 7 guesses or fewer. With strategy C, only 86 of the 5040 answers took 7 guesses, and nearly half were solved in 5.

Guesses with strategy CNumber of answers
1 guess1
2 guesses4
3 guesses59
4 guesses568
5 guesses2423
6 guesses1899
7 guesses86

These are the results of these three strategies. A cleverer strategy might bring the average down even further.

“All new symbols” is not always best for the 2nd guess

When a person plays, guessing only different symbols on the 1st and 2nd guesses is easy to follow and recommended (Tips for Bulls and Cows). But when we calculated, it was not always the best.

With 4 digits, when the 1st guess “0123” got 0 hits and 1 blow (1440 left), comparing candidates for the 2nd guess gave this.

2nd guessAverage leftWorst case left
4567 (all new symbols)about 295504
1045 (2 old symbols + 2 new symbols)about 254408

Moving the old symbols to new places while mixing in new symbols splits the candidates better. When you learn that some of the first symbols are in the answer, using them in different places gives you information about places at the same time, which is probably why. On the other hand, when the 1st guess got 0 hits and 0 blows (360 left), the math also said all new symbols such as “4567” were best.

A way of thinking a person can use as a “winning strategy”

It is hard to carry out the computer’s strategies in your head as they are, but the way of thinking is useful.

  1. Any 1st guess is fine.
  2. For the 2nd guess, use the symbols you found to be in the answer in different places, and mix in new symbols.
  3. From the 3rd guess on, pick rows that do not contradict the clues. When few candidates are left, write them out and compare.

The app’s target numbers (6 for 3 digits, 7 for 4 digits) are the same as the numbers a clever strategy always reaches in the calculation above. If you can solve it within the target, you are quite skilled. The average number of guesses including 5 to 7 digits is in How Many Guesses on Average?, and how to turn a strategy into a program is in Solving It with a Computer.