Mastermind is a code breaking game for two players. The code maker lays out a row of n coloured pegs as the code and hides it from the other player. The same colour may be used more than once.
The code breaker tries to work out the code by making guesses, each of them a row of n coloured pegs. After every guess the code maker reports two numbers r and s.
- r is the number of pegs that match in both colour and position.
- s is the number of the remaining pegs that match in colour but sit in a different position.
Once a peg of the code has been paired with a peg of the guess, neither of them can be paired again. For example, if the code is BACC and the guess is CABB, the A in the second position matches in colour and position, so r is 1. Among the other three positions only one B and one C match in colour, so s is 2. The guess holds two B pegs while the code holds one, so only one of them is paired.
Given a code and a guess, compute r and s.