Bulls & CowsPlay free

Bulls & Cows solver

Type each guess and its score, and the solver shows every secret code that still fits, plus the best next guess. It works with 3, 4 or 5 digits, with or without a leading 0. With 4 digits it cracks any code in 7 guesses or fewer, 5.18 on average.

GuessBullsCows

Enter a guess and its score to start. Not sure how to open? Any code with different digits, like 1234, is as good as any other.

How to use it

  1. Pick the rules: how many digits, and whether the secret code may start with 0 (it can’t in our game; classic paper rules often allow it).
  2. Enter each guess and the score it got: bulls are right digits in the right spot, cows are right digits in the wrong spot.
  3. Read the result: how many codes still fit, the codes themselves once there are few enough, and the guess that narrows them down fastest. Tap Use this guess to add it.

Worked example

The secret is 4271. Following the solver’s advice takes 4 guesses:

GuessBullsCowsCodes left
123412207
13560148
4217221
427140solved

Notice the second guess, 1356: it can’t be the secret (the first score says 1 is not in the first spot), but it splits the 207 codes left better than any code that could still win. Good players make that trade too.

How it picks a guess

For each possible next guess, the solver works out how the codes still in play would split across the possible scores, and picks the guess that leaves the fewest codes on average. Ties go to the guess with the smallest worst case, then to one that could win straight away. With 5 digits and many codes left, it checks a wide sample of guesses instead of all of them, so it stays fast.

DigitsPossible codes (no leading 0)With leading 0Solver averageSolver at most
36487204.936
44,5365,0405.187
527,21630,240≈5.7–

Averages are for codes without a leading 0, measured by playing every possible 3- and 4-digit code (5 digits: 1,000 random games). More on openings and what each score means in the strategy guide.

Questions

How does the Bulls and Cows solver work?

It lists every possible secret code, removes each code that would not have given the scores you entered, and then tries every possible next guess to find the one that leaves the fewest codes on average.

How many guesses does the solver need?

With 4 different digits and no leading 0 (4,536 possible codes), it cracks every code in at most 7 guesses and 5.18 on average. With 3 digits it needs at most 6 guesses, 4.93 on average.

What is the best first guess?

Any guess with all different digits, such as 1234. Every first guess splits the codes the same way, so what matters is choosing the second guess from the first score.

Can the secret code start with 0?

In the Play Bulls & Cows game it can’t, which gives 4,536 possible 4-digit codes. Classic paper rules often allow it, which gives 5,040. Tick “Code can start with 0” for those rules.

It says no code fits. What went wrong?

One of the scores was probably entered or given wrongly: a common slip is counting a digit as both a bull and a cow. Check each row, or remove rows one by one to find the one that doesn’t agree with the others.

Can I use it while playing a friend?

It’s best for learning, checking a finished game or beating the computer. Against a friend, agree first: a solver makes it a very short game.

Play Bulls & Cows freeHow to play