Puzzles, Maths and Algorithms: Bulls and Cows
Bulls and Cows is a two player game. First player thinks of a N digit secret number and second player guesses that number. This is done by second player making a guess and first player telling the number of bulls and cows in the guess. If the digits of guess matches secret and they are in right position, it's a bull, if they match but on different position, they are cows. For e.g. Let secret be 0123 and guess be 0012. The guess has 1 bull, 2 cows. The game continues, until second player gets a response of N bulls.
The problem is to write a computer solver for bulls and cows that would try to guess the secret making only a small number of attempts.
https://github.com/n1balgo/algo/blob/master/bulls_cows.py
Read full article from Puzzles, Maths and Algorithms: Bulls and Cows
Bulls and Cows is a two player game. First player thinks of a N digit secret number and second player guesses that number. This is done by second player making a guess and first player telling the number of bulls and cows in the guess. If the digits of guess matches secret and they are in right position, it's a bull, if they match but on different position, they are cows. For e.g. Let secret be 0123 and guess be 0012. The guess has 1 bull, 2 cows. The game continues, until second player gets a response of N bulls.
The problem is to write a computer solver for bulls and cows that would try to guess the secret making only a small number of attempts.
https://github.com/n1balgo/algo/blob/master/bulls_cows.py
Read full article from Puzzles, Maths and Algorithms: Bulls and Cows