I first learnt to play Bulls and Cows at school sometime around 1959. It was known as a 'paper and pencil' game. But within my little crowd of mathematical nerds we did it in our heads. We always played the five digit game.
   I wrote my first game playing computer programs in about 1969 or 1970 and published a version of Bulls and Cows called BULCOW in David Ahl's book "101 Basic Computer Games" in 1973. I'm pretty sure this was the first, published version that guessed the player's number as well as scoring the player's guesses.
   Computers were slow in those days. If you wanted to do anything fast, you wrote in assembler code, specifying the detailed operations that the computer hardware would perform. BULCOW was written in BASIC and tested on a DEC PDP11/20. This machine had 56Kbytes of core memory and every memory access took two microseconds. An instruction that added two numbers and stored the result took eight microseconds. A BASIC program that processed 30,000 possible numbers would have taken several minutes to make a guess, so I had to use some special tricks to get it to play at all.
   Todays ordinary phones and computers are around 20,000 times faster than the PDP11 and recent changes in the way Javascript is processed have made it possible to write reasonably fast code for the web. Javascript running on my iPhone could be a million times faster than that BASIC in 1970.
   Out there, on the web, there are many programs described that play this game. Most of them treat it as a puzzle for the player and don't guess the player's number at all. The few that play both ways seem to stick at the simpler, four-digit version. There are a couple of example programs for teaching that try to do the whole job, but they assume that any 'possible' guess is good enough. Possible means consistent with the scores, so far.
   So here is a program using the popular technology of our age that plays a good game on any device with a recent Web Browser. How often can you beat it?

About Bulls and Cows