Tuesday, December 13, 2005

Cows and Bulls

Cows n Bulls is a game played by any number of players. In the game, a player chooses a 4-digit number (digits may repeat). The chosen number is written down and placed aside. The other player tries to guess the number which the first player has chosen. The player 2 makes attempts (guesses) and the player 1 should give feedback in terms of number of hits and misses.
  1. A hit means that the number is in the correct position.

  2. A miss means that the number is present but in a different position.

The goal of the game is for player 2 to guess the number which player 1 thought of.

Throwing in the computer

Now, we bring the computer into the picture. The computer should ask the player to guess a 4-digit number. The computer should guess the number using the information of hits and misses. The question is how can we program the computer to guess the correct number using only the information provided by way of the hits and misses counts.