# Automated Bulls and Cows Player [duplicate]

This is a code golf challenge to see the shortest implementation of an automated guesser in the pen and paper game bulls and cows.

The game works as follows:

A (usually 4 digit) secret code with only distinct integers 0-9 is picked by one player. A second player guesses codes that each receive a rank. This rank contains 1 bull for every digit that is correctly placed in the guess, and 1 cow for every digit in the guess that is in the secret code, but not in the correct location within the code.

The code should assume a format as follows:

• The combination will be a 4 digit number containing only distinct digits 0-9. (eg. 0123 is valid, 0112 is not)

• After each guess, you will be given a string as a response telling you how many bulls and how many cows are in your answer. It will be formatted as xByC, in which x is the number of bulls and y is the number of cows. (i.e. 4B0C means you have won). You can assume that a made-up method called "rateGuess", which takes your guess as a string will provide the response.

• I will edit the question to contain the game rules. This is the game that was the basis for mastermind, but the questions are different. The question you linked to asks you to rank the guesses, while this question asks you to guess the code assuming a given ranking method. Jan 27, 2015 at 22:16
• Okay, so you want us to write a Mastermind solver. In that case, the question is, how good does it have to be? Does it have to play optimally? And I think we've had several Mastermind-solving questions as well. There's this for code golf and this for a code challenge. Jan 27, 2015 at 22:19
• I hadn't seen any mastermind solver questions, but that could be because I am used to referring to the game as bulls and cows, and I didn't see any results for that name. The only criteria that the answer is ranked by in this case will be size of implementation. Jan 27, 2015 at 22:21
• But if you don't require optimal play, I could just submit random guesses. There's got to be some (objective) criterion for how well it should perform if you want to make this a code golf. Jan 27, 2015 at 22:22

Ofql{T4^UT4