Search for a tool
Bulls and Cows Solver

Tool/Solver to automatically solve a Bulls and Cows game by finding the secret code in as few attempts as possible.

Results

Bulls and Cows Solver -

Tag(s) : Board Games

Share
Share
dCode and more

dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!


Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!


Feedback and suggestions are welcome so that dCode offers the best 'Bulls and Cows Solver' tool for free! Thank you!

Bulls and Cows Solver

Bulls and Cows game solver






Bulls and Cows Word Solver




See also: Wordle Solver — Lingo Solver

Answers to Questions (FAQ)

What is Bulls and Cows? (Definition)

Bulls and Cows (or Cows & Bulls, or Pigs and Cows) is a logic game based on deduction in which the player must guess a secret code in as few attempts as possible. The game is typically played by two players with distinct roles: the first chooses a secret code (made of digits, letters, or symbols), and the second one tries to guess it. After each guess, feedback is given in terms of “bulls” and “cows”: bulls indicate correct symbols in the correct position, while cows indicate correct symbols in the wrong position. The game ends when the secret code is fully discovered.

How to use the Bulls and Cows solver (syntax)?

The Bulls and Cows solver can be configured by code length (number of positions) and by the number of possible symbols, depending on the game to solve.

The syntax to use is CCCC A B where CCCC is a guess, A is the number of “bulls” (correct symbols in the correct position), and B is the number of “cows” (correct symbols in the wrong position).

In the classic version, the code has 4 positions and uses digits (0–9), but any combination of letters, digits, or symbols can be used.

For a code of size N, each guess must contain N characters followed by 2 numbers indicating the feedback (bulls and cows). Separate each guess with a line break.

Each character represents a chosen symbol. It is recommended to use distinct characters to avoid ambiguity.

Example: ABCD 2 0 means 2 symbols are correct and well placed, and 0 are correct but misplaced.

It is also possible to use wildcards (unknown positions indicated by ?, *, - or _) both in guesses and in scores.

Example: AABC 1 2 means 1 bull and 2 cows

Example: A--- 0 1 (with - as wildcard)

Example: ABC 1? (unknown number of cows)

What is the optimal strategy for Bulls and Cows?

According to Donald Knuth, in an equivalent setup (4‑position code with 6 possible symbols), the code can be found in at most 5 steps. The algorithm is:

1 - Generate the set E of all possible codes.

2 - Use 1122 (or an equivalent) as the first guess.

3 - If correct, the game ends. Otherwise, remove from E all codes that are inconsistent with the feedback (bulls and cows).

4 - For each remaining untested guess, evaluate how many possibilities from E would be eliminated for each possible feedback. Score each guess by its worst‑case elimination (the minimum number eliminated). Choose a guess that maximizes this score, preferably one from E. Repeat from step 3.

This guarantees that the code will be found in 5 steps or fewer.

What is the hardest combination to guess in Bulls and Cows?

Mathematically, if the player's strategy is known, some combinations can be harder than others. However, with an optimal strategy (like Knuth's), all combinations can be solved in 5 steps or fewer.

If the strategy is unknown, no combination is inherently harder than another.

In practice, some patterns are trickier for humans:

— Repeated symbols are often overlooked.

— Uncommon symbols (high digits, rare letters) are tested later.

— Non-intuitive patterns (e.g., 1221, 5656) are harder to anticipate.

Some commonly cited difficult combinations include: 1221, 2354, 3311, 4524, 5656, 6643.

What are Bulls and Cows variants?

A well-known variant is the Mastermind game, which uses colors instead of digits or symbols, typically played with a physical board and pegs.

Another variant uses words instead of symbols, greatly increasing the number of possible combinations.

It is also possible to allow empty positions (blanks), if agreed upon by players.

Bulls and Cows is often used as a basis for puzzles or mini-games in software and video games.

Who invented Bulls and Cows?

Bulls and Cows is an old game with no clearly identified inventor. It was played long before Mastermind, often as a pencil-and-paper number game.

Source code

dCode retains ownership of the "Bulls and Cows Solver" source code. Any algorithm for the "Bulls and Cows Solver" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Bulls and Cows Solver" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Bulls and Cows Solver" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.

Cite dCode

The content of the page "Bulls and Cows Solver" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).

Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).

To cite dCode.fr on another website, use the link: https://www.dcode.fr/bulls-and-cows-solver

In a scientific article or book, the recommended bibliographic citation is: Bulls and Cows Solver on dCode.fr [online website], retrieved on 2026-04-21, https://www.dcode.fr/bulls-and-cows-solver

Need Help ?

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Questions / Comments

Feedback and suggestions are welcome so that dCode offers the best 'Bulls and Cows Solver' tool for free! Thank you!


https://www.dcode.fr/bulls-and-cows-solver
© 2026 dCode — The ultimate collection of tools for games, math, and puzzles.
â–˛  
Feedback