Your guess gets 0 bulls and 4 cows. Have you missed every digit, or found them all?
You have found all four digits. Every one is somewhere in the secret code, but each is in the wrong position. That distinction is the heart of Bulls and Cows: work out which digits belong, then where they belong.
Bulls and Cows rules
A bull is a correct digit in the correct position. A cow is a correct digit in a different position. A digit that is absent from the secret earns neither. These are the definitions used in Maplesoft’s Bulls and Cows explanation.
For every example and exercise in this article, use these rules:
- The secret and each guess have four digits chosen from 0 to 9.
- No digit repeats within a secret or guess.
- The first digit cannot be 0; zero is allowed elsewhere.
- Feedback gives two totals, without identifying which digits earned them.
- Four bulls means the code is solved.
These are our teaching rules for a paper game. Versions can differ, so check the digit count, repetition rules, and treatment of zero before starting a different version. No app controls or settings are assumed here.
To play with a friend, one person writes down a secret without showing it. The other records a guess and its feedback, then uses those clues for the next guess. Keep the secret unchanged throughout the round.
How to read the clues
Suppose the secret is 5831 and the guess is 5138:
| Guessed digit | Comparison with the secret | Result |
|---|---|---|
| 5 in position 1 | The secret starts with 5 | Bull |
| 1 in position 2 | The secret has 1 in position 4 | Cow |
| 3 in position 3 | The secret has 3 in position 3 | Bull |
| 8 in position 4 | The secret has 8 in position 2 | Cow |
The feedback is 2 bulls, 2 cows. Each digit counts once: a bull does not also count as a cow.
You can identify those matches because the secret is visible in this explanation. During play, the two totals alone do not tell you which digits are correctly placed.
A complete worked deduction
Here is an original teaching round. Imagine you cannot see the secret. Your first three guesses produce:
| Guess | Bulls | Cows |
|---|---|---|
| 2467 | 0 | 0 |
| 1358 | 0 | 4 |
| 5138 | 2 | 2 |
First, eliminate absent digits. The result for 2467 excludes 2, 4, 6, and 7 everywhere in the code. Zero bulls alone would only exclude their positions; zero cows as well excludes the digits entirely.
Next, identify the complete set. The result for 1358 says the secret uses exactly 1, 3, 5, and 8. None is in its guessed position. Zero and 9 are therefore excluded too.
There are nine arrangements of those four digits that put all four in different positions from 1358:
3185 3581 3815
5183 5813 5831
8135 8513 8531
Now apply the third clue. Which arrangements would give 5138 exactly two bulls? Every arrangement already contains the same four digits, so the other two matches will be cows.
| Candidate | Bulls against 5138 | Keep it? |
|---|---|---|
| 3185 | 1 | No |
| 3581 | 0 | No |
| 3815 | 0 | No |
| 5183 | 2 | Yes |
| 5813 | 1 | No |
| 5831 | 2 | Yes |
| 8135 | 2 | Yes |
| 8513 | 0 | No |
| 8531 | 1 | No |
Three candidates remain: 5183, 5831, and 8135. Choosing one now might succeed, but the clues have not yet forced a unique answer.
Try 3185. This is a valid guess even though it cannot itself be the secret: it conflicts with the third clue. A guess can still help distinguish the remaining possibilities.
The feedback is 0 bulls, 4 cows. Compare that with each survivor:
- Against 5183, the guess 3185 would give 2 bulls and 2 cows.
- Against 5831, it gives 0 bulls and 4 cows.
- Against 8135, it would give 2 bulls and 2 cows.
Only 5831 fits. Guess it to receive 4 bulls, 0 cows and finish the round. Every elimination followed from recorded feedback; none required knowing the secret in advance.
A four-step deduction strategy
Use this routine to organise your reasoning, rather than as a promise to solve every code within a fixed number of guesses.
- Track digit membership. Add bulls and cows to find how many guessed digits belong somewhere in the code. For example, testing 1234 and 5678 covers eight different digits. If their totals are one and two matches respectively, the fourth secret digit must be 0 or 9. This is one possible exploration pattern; choose your next guess in light of the feedback rather than always following a fixed opening.
- Track positions separately. Zero bulls rules out each guessed digit at its tested position, but does not establish which digits belong. Do not treat a cow as an identified digit: feedback gives totals, not labels. A zero-bull clue is useful without being universally better than a clue containing bulls.
- Choose a guess that separates possibilities. Compare the feedback a proposed guess would receive from the surviving candidates. Different results can help tell them apart. The 3185 probe above distinguishes 5831 from the other two survivors, even though it cannot itself win.
- Check every candidate against the full history. Keep only possible secrets that reproduce all recorded bull and cow totals. A probe may conflict with earlier clues; a proposed final answer must not.
A short practice puzzle
Use the same four-digit, no-repeat rules. The secret is one of these candidates:
4926 4962 9426 9642
You receive two clues:
| Guess | Bulls | Cows |
|---|---|---|
| 4926 | 2 | 2 |
| 9246 | 0 | 4 |
Which candidate survives both? Try checking them before reading on.
Answer: 4962. The first clue excludes 4926, which would score four bulls, and 9642, which would score zero. That leaves 4962 and 9426.
For the second guess, 4962 gives zero bulls: 9, 2, 4, and 6 are all misplaced. But 9426 would give two bulls, for 9 in the first position and 6 in the fourth. It therefore fails the second clue.
Keep the whole history
Before accepting a candidate, compare it with every previous guess. Fitting the newest clue is only part of the job. Also keep digit membership separate from position: knowing that 8 belongs does not mean you know where it goes.
Questions about the rules and strategy
Can the secret start with zero or repeat a digit?
Not under this article’s teaching rules: leading zeroes and repeated digits are excluded. Other variants may allow them. Agree on the rules before playing, because they change the candidate set and how clues are interpreted.
Must every guess still be a possible secret?
Not in our paper-game rules. A guess with four different digits and no leading zero is allowed even when earlier feedback rules it out as the answer. Use such a probe only when its possible responses would help distinguish the remaining candidates; it spends a turn without a chance to finish immediately.
Does this strategy guarantee a solution in five guesses?
No. The worked round finishes in five guesses, but one example does not prove a bound for every secret. This guide offers a human deduction routine, not a proven optimal decision tree. Avoid judging a useful information-gathering move solely by whether it wins at once.
If you enjoy this kind of deduction, the Bulls & Cows: Code Breaker project page introduces my Android game. For a paper round, all you need is a secret, a guess history, and feedback you can check carefully.
Originally published on Alpaca Apps.