Mastering 1A2B (Bulls and Cows): Strategy, Algorithms, and the Science of Deduction

1A2B — known internationally as Bulls and Cows, and also as Mastermind (in peg-colour form) — is one of the most elegant information theory puzzles ever devised. In its classic 4-digit form, you are trying to guess a 4-digit secret number (all digits unique, no zeros) in as few guesses as possible, using only the feedback you receive each round.

The feedback is deceptively simple:

A (Bulls): How many digits are correct AND in the correct position.

B (Cows): How many digits are correct but in the WRONG position.