🔢 Guess the Number

Enter a 4-digit number with no repeating digits and use the xA xB clues to deduce the answer!

Guesses {{ attempts }}
Left {{ remaining }}
{{ msg.text }}
{{ history.length - idx }} {{ entry.guess }} {{ entry.A }}A {{ entry.B }}B
Possibilities ({{ remaining }})
{{ r }} …and {{ moreCount }} more
🎉
Congratulations!
{{ attempts }} Guesses

 The Rules in One Minute

The computer picks a 4-digit number with no repeated digits (4 of the digits 0–9, so 10×9×8×7 = 5,040 possibilities). After each guess you get:

  • A (bulls) — right digit, right position.
  • B (cows) — right digit, wrong position.

Example: answer 1234, guess 1357 → 1A1B (the 1 is exactly placed; the 3 exists but sits in the wrong slot). Reach 4A0B and you win. Bulls and Cows has been played on paper for well over a century — two players, two secret numbers, alternating guesses — and it's the direct ancestor of games you already know.

 The Information Math: Why ~6 Guesses Is the Wall

Identifying one answer among 5,040 requires log₂5040 ≈ 12.3 bits of information. Each guess returns one of at most 14 possible A/B responses — at best log₂14 ≈ 3.8 bits — so a perfect player needs at least four guesses in theory, and exhaustive computer analysis shows an optimal strategy wins in at most 7 guesses, averaging about 5.2. Humans landing consistently at 6 are playing near-optimally.

The practical translation of "maximize information": your opening guesses should cover digits, not chase the answer. Open with 1234 then 5678 — the two responses jointly tell you how the answer's four digits split across those sets (with 0 and 9 inferred). A response of 0A0B is a gift, eliminating every candidate containing any of those four digits. And when a known digit's position is unknown, move only that digit between guesses so the A/B change is attributable — one variable at a time, exactly like debugging.

The "Possibilities" panel plays the computer's role: it filters the candidates consistent with your entire history. The count shown is effectively a live scoreboard of how many bits each guess bought you. Try reasoning first, then open the panel to check yourself.

 Mastermind, Knuth, and Wordle: One Mechanic, Three Eras

In 1970, an Israeli postmaster turned Bulls and Cows into the peg-board game Mastermind, which sold over 50 million copies. It then became a computer-science classic: Donald Knuth proved in 1977 that Mastermind's 1,296 codes can always be cracked in five guesses using a minimax rule — pick the guess whose worst-case response eliminates the most candidates. The same idea powers every Bulls and Cows solver, including the candidate filter on this page.

Fifty years later, Wordle re-skinned the mechanic once more: letters instead of digits, green for A, yellow for B. If you've internalized Bulls and Cows strategy — information-rich openings, hypothesis isolation, elimination bookkeeping — you already know how to play Wordle well. The lineage runs unbroken from schoolyard paper games to a New York Times acquisition.

 Frequently Asked Questions

Why can't digits repeat?

The classic rules forbid repeats, which keeps the A/B feedback unambiguous — each digit is simply present or absent, placed or misplaced. Variants with repeats exist but need messier counting rules; learn the clean version first. Repeated digits in your guess are rejected as invalid.

What does the "Left" counter mean?

The number of candidate answers still consistent with all your feedback so far — 5,040 at the start, ideally collapsing fast. Watching how much each guess shrinks it teaches information-efficient guessing better than any tutorial.

What should I guess when stuck?

Open the Possibilities panel and pick from the list — anything there is guaranteed consistent with your history. If only a handful remain, choose the one whose possible responses split the rest most evenly; that minimizes your worst case, which is Knuth's minimax idea in miniature.

Is this good brain training for kids?

Excellent — it exercises number sense, hypothesis testing, and patience, with no failure penalty beyond another guess. For younger children, play the two-player paper version with 3-digit secrets to shorten the deduction chain.