Bulls and Cows

Guess a secret number and every try comes back with two counts: bulls for the digits you put in exactly the right place, cows for right digits in the wrong spot. Narrow it down and crack it in as few guesses as you can.

How to play

No digit is repeated in the hidden number, which rules out a great many guesses before you begin.

  1. Tap digits to build a guess No digit may repeat within a guess, so a digit already used is greyed out. Back removes the last one.
  2. Submit and read the counts Bulls are right digit, right place. Cows are right digit, wrong place. A digit is never counted twice.
  3. Watch the possibilities The scoreboard shows how many numbers still fit every answer so far. That figure only ever goes down.
Full instructions

    In depth

    Cracking a hidden number with logic alone

    How the feedback from each guess narrows the search, why a guess that matches nothing is often the best one you can make, and how to read the possibilities counter to know exactly where you stand.

    Screenshot: How to play Bulls and Cows
    How to play Bulls and Cows as it appears when the page opens.

    What the game asks of you

    A number is hidden. Every digit in it is different. Your job is to find it within a fixed number of guesses. After each guess you get two counts. Bulls tells you how many digits are in exactly the right position. Cows tells you how many digits appear in the number but sit in the wrong spot. A digit only counts once, so it is either a bull, a cow, or absent.

    That is the entire rule set. There is no colour code, no board to look at, and no luck involved once the number is set. The game is pure deduction. Every piece of information you need is already in the feedback you have been given. The question is whether you can extract it.

    Choosing a difficulty

    Three settings control the length of the hidden number. A three-digit number drawn from the digits zero through nine gives you ten guesses. A four-digit number also gives ten. A five-digit number gives twelve, because the search space is much larger.

    With three digits there are 720 possible numbers. With four there are 5,040. With five there are 30,240. Those figures are the count of every arrangement of that many different digits picked from ten. The game shows this total before your first guess, and it is the number you are trying to drive down to one.

    Controls and how a turn works

    Tap a digit on the number pad to add it to your guess. Once a digit is in the guess it is greyed out, because no digit may repeat. If you make a mistake, press Back to remove the last digit. When the guess is the right length, the Guess button lights up.

    On a keyboard, the number keys type digits, Backspace removes the last one, and Enter submits the guess. The same no-repeat rule applies. If you press a digit that is already in the current guess, the game tells you and ignores the press.

    After you submit, the guess appears in the log with its bull and cow counts. The scoreboard updates with three facts: how many guesses you have left, how many numbers are still possible, and the highest bull count from any guess so far.

    Reading the possibilities counter

    Below the scoreboard is a number labelled Still Possible. It starts at the total count for your chosen length. After every guess, the game checks every number in that set and throws away any that would not have produced the exact same bull and cow counts. What remains is the honest size of the search space.

    This is not a hint about the answer. It is arithmetic, and you could do it yourself with a pencil and enough patience. But watching it is useful. A guess that drops the count from 5,040 to 600 told you a lot. A guess that drops it from 600 to 580 told you almost nothing. The size of the drop is a direct measure of how good your guess was.

    When the counter reaches one, there is only one number that fits everything you know. That is the answer. You do not need to guess it by feel at that point. You have already proved it.

    Why a zero result is so valuable

    A guess that comes back with zero bulls and zero cows feels like a failure. It is usually the opposite. If you guess four digits and get nothing, you now know that none of those four digits appear in the number at all. That rules out four of ten digits in a single move.

    Compare that with a guess that returns one bull and zero cows. You know one of your four digits is correct and in the right spot. But which one? You have narrowed the search a little, but you still have three unknowns mixed in with one known, and you cannot tell them apart without more guesses.

    The zero result is clean. It partitions the digit set into two groups with no ambiguity. Every future guess can be built entirely from the six remaining digits. That is why experienced players sometimes guess numbers they suspect are wrong on purpose. They are fishing for zeros.

    A worked example at four digits

    Suppose you guess 1234. The answer comes back: 0 bulls, 2 cows. You know two of those four digits are in the number, but none of them is in its correct position. You do not know which two.

    Next you guess 5678. The answer: 0 bulls, 1 cow. Now you know one of those four digits is in the number. Combined with the first guess, three of the hidden digits come from those eight, and the fourth is either 0 or 9.

    For your third guess you try 2156. You get 1 bull, 1 cow. Because 5 and 6 were in the second guess and only got one cow between them, you can start comparing overlaps. The digit that was a cow in guess one and now appears in the right place is your bull. The cow here is a digit you already knew was present but still have not pinned down.

    This kind of cross-referencing is the heart of the game. Each guess on its own says little. Two guesses together say much more. Three begin to corner the answer.

    Strategy for the opening guesses

    Your first guess cannot be wrong. Every number with no repeated digits is equally good as a starting point, because you have no information yet. Pick anything and move on.

    The second guess should share no digits with the first. If the first guess was 1234, try 5678. Between the two of them you will have tested eight of the ten digits. The feedback from both together tells you how many of the hidden digits live in each group.

    If both guesses together account for all the cows and bulls you need, the two missing digits are 0 and 9, and you know neither of them is in the number. If the counts do not add up to the full digit length, the missing ones must include at least one that is part of the answer.

    From the third guess onward, you should be rearranging known digits rather than testing new ones. Shuffle the digits that got cow results into different positions. When a cow turns into a bull, that digit is locked in place.

    Turning cows into bulls

    Once you know which digits are in the number, the remaining work is all about position. Suppose you have four digits and two of them are bulls already. The other two are cows, meaning they are present but swapped.

    Swap those two and leave the bulls where they are. If both cows become bulls, you have found the number. If one becomes a bull and the other stays a cow, something else is going on and you need to revisit your assumptions.

    The common mistake is to keep introducing new digits when the total of bulls plus cows already equals the digit length. If you have a four-digit game and one guess gave you 1 bull plus 3 cows, every digit in that guess belongs in the answer. Stop exploring. Start rearranging.

    Mistakes that cost guesses

    • Repeating a digit inside a guess. The game will stop you, but thinking about it costs time and focus.
    • Ignoring the cow count. A cow is just as much information as a bull. It tells you a digit is present, and it tells you one position where that digit does not go.
    • Changing too many things at once. If you move three digits between guesses and the result changes, you cannot tell which move caused it. Change one or two positions at a time.
    • Treating the possibilities counter as a target. It is a measure, not a goal. A guess that cuts it in half is great, but you cannot always predict which guess will do that. Focus on the logic.
    • Guessing randomly when the counter is low. If only twelve numbers remain, you can often deduce the answer from the feedback you already have. Take a moment to read the log before spending a guess.
    • Giving up on a zero result. New players sometimes restart after getting zero bulls and zero cows. That answer just handed you four confirmed negatives. Use them.

    How scoring and winning work

    You win when every digit is a bull. Your score is the number of guesses it took. The fewer guesses, the better. The game tracks your best score for each difficulty.

    If you run out of guesses, the hidden number is revealed. There is no penalty beyond the lost game. You can start a fresh round immediately by pressing New Game or by switching the difficulty, which also starts a new round.

    Everything stays on your device

    The hidden number is picked by your own browser. Your guesses are checked locally. The possibilities counter is filtered in memory on your machine. Nothing about your game is sent anywhere. You could disconnect from the internet after the page loads and every feature would still work, because there is no server involved in the game at all.

    Help

    How to play Bulls and Cows

    No digit is repeated in the hidden number, which rules out a great many guesses before you begin. After each try you are told not only the bulls and cows but how many numbers are still consistent with everything so far, a count that falls sharply when a guess is chosen well and barely moves when it is not.

    Tap digits to build a guess

    No digit may repeat within a guess, so a digit already used is greyed out. Back removes the last one.

    Submit and read the counts

    Bulls are right digit, right place. Cows are right digit, wrong place. A digit is never counted twice.

    Watch the possibilities

    The scoreboard shows how many numbers still fit every answer so far. That figure only ever goes down.

    Rule digits out on purpose

    A guess that comes back with nothing at all removes several digits from consideration in one go.

    Finish before the guesses run out

    Get all bulls within the limit and you win; the fewer guesses, the better the score.

    What the possibilities counter really is

    It is not a hint about the answer. After every guess the game takes the full list of numbers with the right length and no repeated digit — five thousand of them for four digits, thirty thousand for five — and throws away every one that would not have produced exactly the counts you were given. What is left is the honest size of the search space. Watching it fall from five thousand to a dozen is the clearest picture there is of what a well-chosen guess actually buys, and it is why a guess that matches nothing often beats one that matches something.

    Good to know

    Zero is the most useful answer

    No bulls and no cows tells you four digits are definitely absent, which is more information than one bull usually gives.

    Move digits, do not replace them

    Once you know which digits are in the number, keep guessing the same digits in different orders to turn cows into bulls.

    Total matches settle first

    Bulls plus cows is how many of your digits are in the number at all. Nail that count before worrying about position.

    The first guess barely matters

    Every starting number is equally good. What matters is that the second guess reacts to what the first told you.

    Common questions

    Can a digit repeat in the hidden number?
    No. Every digit in it is different, and your guesses have to be the same.
    Can a digit be both a bull and a cow?
    No. Each digit of your guess counts once — as a bull if it is in the right place, otherwise as a cow if it appears elsewhere.
    Can the number start with zero?
    Yes. It is treated as a sequence of digits, not as a value.
    Is the possibilities count a hint?
    Only in the sense that arithmetic is. It is worked out from your own guesses and the answers you were given, and nothing else.
    How is this different from the coloured peg version?
    The peg version uses colours and usually allows repeats. Bulls and cows uses digits with no repeats, which makes deduction sharper and memory harder.