How to play Bulls And Cows

The objective is to deduce a pattern of four coloured pegs chosen at random by the computer. The four pegs can be any combination chosen from the six colours green, blue, red, white, black and yellow.

Each peg of the right colour correctly placed is indicated by a black Bull and each peg of the right colour but wrongly placed is indicated by a white Cow in the "Clues" column.

Click on the button 'New Game' to start playing.


The line number 1 turns black indcating that input for the first row is expected :

help 1


Click on the colour buttons to place the first four pegs. When four pegs have been placed clues consisting of black Bulls or white Cows will be displayed :

help 2

The black Bull indicates that one peg is in the right position and is the right colour. So at this stage we know that there is one green peg in the correct position.


Clicking the green button followed by the blue button three times produces the result below :

help 3

The black Bull indicates that there is one peg of the correct colour and in the right place. The white Cow indicates that there is also one peg of the right colour in the wrong position. It can be deduced that the green peg is not in the correct position as this would necessarily mean that the blue peg would be in the correct position. The leftmost peg cannot be green. It can further be deduced that the first peg cannot be blue as this would have produced two white Cows.


Now let us try and get some more clues :

help 4

It is easy to see that there are no white pegs in the sought pattern as the number of Bulls and Cows has remained unchanged. It is not possible at this stage to tell which peg is in the correct position.


Using two red pegs and changing the position of the blue peg :

help 5

There are no red pegs required but the green peg and the blue peg are correct.


Next we will test if there are any yellow pegs in the required combination :

help 6

So there are no yellows but the green peg and the blue peg are still in the correct position.


There are only black pegs left to try :

help 7

Four black Bulls means the solution has been found!


If after ten attempts the combination has not been found then the solution is displayed and the game ends.