Gamer Nation

Bulls and Cows

The code behind this board is four digits long and never uses a digit twice, which is why your guesses have to obey the same rule. Each row you submit is answered with two counts: bulls, the digits you put in the right column, shown against the filled dot, and cows, the digits that are in the code but in a different column, shown against the hollow one. The digits run 1 to 9 and then 0, which is the tenth peg. Ten rows, 5,040 codes, and everything happens in the page.

The sum that only works because digits cannot repeat

Add the bulls to the cows and you have the number of your four digits that appear in the code at all. That reading is exact here and it is exact only because neither the code nor a legal guess ever repeats a digit: each of your digits is either in the code, in which case it is counted once, or it is not. On a board that allows repeats the same sum is a much vaguer thing, since two of your pegs can compete for one peg in the code.

So an answer of one bull and one cow says three things at once, and most players take only the first two. Two of your digits are in the code. One of those two is in the right column. And – this is the part left on the table – the other two digits you played are not in the code anywhere, which retires them from every column for the rest of the game. A good part of what any row buys you is the digits it rules out rather than the ones it confirms.

Why a repeated digit is refused

Put the same digit in two slots and the row will not go anywhere. It is outlined instead, an exclamation mark appears where the counts belong, and the guess is not taken – so a mistyped row costs you nothing but the retyping. The rule is not fussiness. Ten choices for the first column, nine for the second, eight for the third and seven for the last gives 5,040 codes rather than the 10,000 four-digit strings you could otherwise write down: the no-repeat rule throws away 4,960 possibilities before you have played a row, and it is what makes bulls plus cows mean exactly what it means above.

What your first row is worth, answer by answer

Every legal opening on this board is worth precisely the same as every other one. Whichever four distinct digits you start with, the 5,040 codes split into the same fourteen groups in the same sizes, because relabelling digits is just relabelling. There is no clever opening to be found here: whatever you play, the worst answer to it leaves exactly 1,440 codes standing. What differs is which answer you get, and they are very far from equally likely.

Bulls Cows Codes left
0 0 360 all four of your digits absent; the code uses the other six
0 1 1,440 the commonest answer of the fourteen
0 2 1,260
0 3 264
0 4 9 all four digits, every one misplaced
1 0 480
1 1 720
1 2 216
1 3 8
2 0 180
2 1 72
2 2 6
3 0 24 the odd digit is not in the code at all
4 0 1 you have broken it on the first row

The middle column is doing double duty, and noticing that is worth more than memorising any row of it. The number of codes an answer leaves standing is also the number of codes that produce it, so divide any figure in that column by 5,040 and you have your chance of being given that answer. Informative and rare are the same property here, exactly rather than roughly. Which is why 0-1, the answer you are most likely to get, is also the worst one to get: 1,440 codes produce it and 1,440 survive it. A blank row – no bulls, no cows – cuts the field to 360 and arrives about once in fourteen openings, and nine of the fourteen answers cut deeper than a blank does, every one of them rarer in exactly that proportion. Fourteen groups, and the good one is rare: that is the shape of this game, and it is why the middle rows feel like such slow going.

The blank you can only be given once

After a blank row you know four digits are absent, so the code is built from the six you have not tried, and there are 360 ways to do that. Now play four of those six. Your four and the code’s four are both drawn from the same six digits, so they must share at least two – four and four will not fit into six any other way. Every such row is guaranteed to score at least two, and a second blank is arithmetically impossible: it would leave only two digits to build a four-digit code from.

This is worth knowing before you waste a row hoping for another clean sweep. Once you have had one blank, the rest of the game is division rather than elimination, and the honest plan is to keep splitting the six remaining digits rather than to keep looking for absences that cannot be there.

Where the game comes from

Long before any of this ran on a screen it was a two-person game played with paper: one player writes down a code of four different digits, the other calls out guesses, and the setter answers each one with two numbers rather than any commentary. The name for those two numbers is the name of the game, and the bulls and cows game has been played under it for decades. What this page adds is a setter who cannot miscount and does not get bored – the mechanic itself is old, free, and belongs to nobody.

What the star does here, and what it will not claim

On some boards on this site the star reports how many codes are still consistent with your rows. Here it does not, and that is deliberate rather than missing. The solver keeps a working list capped at 1,400 codes; 5,040 is well over that, so on this board it reasons from an evenly spread sample of the codes still standing rather than from every last one. It will still fill your row with a strong guess. It just will not print a survivor count it cannot stand behind.

The one control that behaves differently here

Everything under the board works as it does on the other two code boards – a peg drops into the highlighted slot, the tick submits, the backspace symbol clears, and the digits and arrow keys do the same job from the keyboard. There is one exception, and it is the no-repeat rule enforcing itself. A row carrying the same digit twice is refused before it is ever scored: the row is outlined, an exclamation mark appears where the two counts belong, and none of your ten is spent on it.

That refusal is doing real work rather than being tidy. It guarantees every row on the board is itself a legal code, which is the condition that lets bulls plus cows be read as a plain count of your digits that appear in the answer at all. It also means the only way to waste a row here is deliberate: submit a legal guess you had already ruled out, and the board will take it. Win or lose, the code appears as the final row.