Question: The bulls and cows game is a code-breaking game designed for two or more players. Each player chooses a secret code of 4 digits from

The bulls and cows game is a code-breaking game designed for two or more players. Each player chooses a secret code of 4 digits from 0 - 9. The digits must be all different. The goal of the game is for each player to guess the other player's secret code.

  1.  
  2. The players in turn present their guesses to the opponents. The opponents respond by telling the players:
  3.  
  4. The number of bulls, i.e. the number of matching digits in their right positions, and
  5.  
  6. The number of cows, i.e. the number of matching digits but in different positions.
  7. Please enter your secret code: 4568 You guess: 1234 Result: 1 bull 

Please enter your secret code: 4568 You guess: 1234 Result: 1 bull and 2 cows Computer guess: 5940 Result: bulls and 2 cows You guess: 1345 Result: 0 bulls and 2 cows Computer guess: 1279 Result: bulls and 0 cows You guess: 4271 Result: 3 bulls and cows Computer guess: 4890 Result: 1 bull and 1 cow You guess: 4281 Result: 4 bulls and 0 cows You win! :)

Step by Step Solution

3.38 Rating (151 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

It seems like youre describing the classic game of Bulls and Cows Players take turns guessing each o... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!