Bulls & CowsPlay free

Bulls & Cows strategy

Open with any four different digits (1234 is as good as anything), then choose each next guess from the score you just got. Do that and you will crack a 4-digit code in about 5 guesses. Our solver checked all 4,536 possible codes: it averages 5.18 guesses and never needs more than 7.

4,536possible 4-digit codes
5.18guesses on average, solver
7guesses at most, solver

New to the game? Read the rules and a worked example first. Every number on this page uses the rules played here: all digits different and the code can’t start with 0.

The numbers by code length

DigitsPossible codesSolver averageSolver at mostRandom fitting guess
36484.936≈5.2
44,5365.187≈5.4
527,216≈5.7–≈5.9

≈ means a simulated average, not an exact count.

Longer codes take surprisingly few extra guesses, because every score also tells you more. Five digits have six times as many codes as four, yet need only about half a guess more.

The best first guess

Any four different digits. Before your first guess every code is equally likely, so the only thing that makes openings differ is the 0, which can’t start the secret code. That splits openings into two groups, and they are almost identical:

First guessCodes left on averageCodes left at worst
1234 (no 0)8301,260
1023 (with a 0)8271,320

We start with 1234: its worst case is smaller, and our solver’s full games average 5.18 guesses from 1234 against 5.22 from 1023. The difference is tiny. Don’t spend time on the opening; spend it on the second guess.

What your first score tells you

All 14 scores 1234 can get, how often each comes up, and how many codes are still possible afterwards:

Score for 1234How oftenCodes left
0 bulls, 1 cow27.8%1,260
0 bulls, 2 cows25.5%1,155
1 bull, 1 cow14.6%660
1 bull, 0 cows9.3%420
0 bulls, 0 cows6.6%300
0 bulls, 3 cows5.6%253
1 bull, 2 cows4.6%207
2 bulls, 0 cows3.6%165
2 bulls, 1 cow1.5%69
3 bulls, 0 cows0.5%23
0 bulls, 4 cows0.2%9
1 bull, 3 cows0.2%8
2 bulls, 2 cows0.1%6
4 bulls (solved)0.02%1

More than half of all games open with one or two cows and no bulls. And 3 bulls with 1 cow never happens: if three digits are in place and all four are in the code, the last one has only one spot left.

Choose the second guess from the score

Many players always open 1234 then 5678. That leaves 192 possible codes on average. Picking the second guess after seeing the first score leaves 135, about 30% fewer. What to do with each kind of score:

A worked game

The secret is 4271 (the same one as in the rules example). The solver cracks it in four guesses:

  1. 207 codes left12341 bull, 2 cows

    Three of 1, 2, 3, 4 are in the code, one of them in its right spot.

  2. 48 codes left13560 bulls, 1 cow

    Only one of 1, 3, 5, 6 is in the code. Since three of 1–4 are in, that one must be the 1 or the 3, so 5 and 6 are out, and 2 and 4 are definitely in. The fourth digit is 0, 7, 8 or 9.

  3. 1 code left42172 bulls, 2 cows

    All four digits are right and two are in place. Only one code fits all three scores.

  4. Solved42714 bulls

    Cracked in 4. About two games in three end in 5 guesses or fewer for the solver.

How often each game length happens

Our solver played all 4,536 possible 4-digit codes, always opening with 1234:

Guesses neededCodesShare
1 or 260.1%
3621.4%
460113.2%
52,35351.9%
61,47932.6%
7350.8%

So if your friend cracks your code in 4, they played well or got lucky; in 3, mostly lucky. For the classic version where a code may start with 0 (5,040 codes), Tetsuro Tanaka proved in 1996 that the best possible average is 5.213 guesses (An optimal MOO strategy).

Tips for playing against a friend

How the computer plays

Test yourself vs the computerPlay a friend online

Questions

What is the best first guess in Bulls and Cows?

Any four different digits. Every opening is almost equally good: 1234 leaves 830 possible codes on average and 1,260 at worst. Openings with a 0 in them leave 827 on average but 1,320 at worst. What matters is choosing the second guess after you see the first score.

How many guesses does it take to win Bulls and Cows?

With 4 digits, a computer solver needs 5.18 guesses on average and never more than 7. Good human players usually take 5 to 7. With 3 digits the solver averages 4.93 guesses and never needs more than 6.

How many possible codes are there?

With all digits different and no leading 0: 648 codes with 3 digits (9 × 9 × 8), 4,536 with 4 digits (9 × 9 × 8 × 7) and 27,216 with 5 digits (9 × 9 × 8 × 7 × 6).

What does 0 bulls and 0 cows mean?

None of the four digits you guessed is in the code, so you can cross all four out. It happens about 1 time in 15 on the first guess, and after 1234 it leaves only 300 possible codes, all made from 0, 5, 6, 7, 8 and 9.

Is Bulls and Cows easier with 3 digits?

Only a little. There are far fewer codes (648 instead of 4,536), but each score tells you less. A solver needs 4.93 guesses on average with 3 digits and 5.18 with 4 digits.

Can you get 3 bulls and 1 cow?

No. If three digits are in the right spots and all four digits are in the code, the last digit can only go in the one spot left, so it would be a bull too.

How we worked this out: we scored every possible guess against every possible code under the rules played here, then let a solver play every 3- and 4-digit code to the end. It picks the guess that leaves the fewest codes on average (with 3 digits, among guesses that still guarantee a win within 6), and may use guesses that can’t be the answer. 5-digit and “random fitting guess” figures are averages over simulated games.

Play Bulls & Cows free