October 13, 2020

Mastering Mastermind

Games offer wonderful playing fields for developing mathematical problem-solving skills.

For educator Mathew Mitchell, the preferred training ground is a classic game called Mastermind. "Students young and old are fascinated by simple yet challenging games," he wrote in his book Mastermind Mathematics: Logic, Strategies, and Proofs.


Mastermind involves hypothesis testing and deductive reasoning, Mitchell noted. It is also an activity that many people of a wide range of ages find highly enjoyable.

In Mastermind, a codemaker secretly selects a sequence of four colors, typically represented by colored pegs. The codemaker can use any combination of colors picked from the six different colors that are available, including two or more of the same color.

A player's goal is to determine the codemaker's hidden sequence, making as few guesses as possible. With each guess, the player displays a sequence of four colored pegs, and the codemaker indicates how many of those pegs are the correct color and in the right position and how many more are the correct color but in the wrong position.

Suppose the pegs are red (R), blue (B), yellow (Y), green (G), white (W), and orange (O).

Codemaker's secret sequence: R W B G
Player's first guess: W Y B O

In this example, the codemaker would indicate that the player has one peg of the right color in the right position and one peg of the right color in the wrong position but would give no clue that the blue peg (B) and the white peg (W) are the relevant choices.

With six colors and four positions, a codemaker can select from 64 (or 1,296) possible combinations. One useful beginning strategy for a player is to find the colors first, then determine the correct positions. By focusing initially on color, you have only 126 possible groupings to consider. Once you have the colors, you need look at no more than 24 possible arrangements of that set of colors.

Once in a while, however, you might find that you need to know one or two positions before you can work out all the colors. "This brings up an important point about strategies," Mitchell remarked. "They do not always work."

Here's one example where position information helps you out. 

Game 1
Guess 1: W R O O 
Three pegs are the right color and in the right position.
Guess 2: W B B B
One peg is the right color but is in the wrong position.

Foundation strategies such as pursuing subgoals (such as colors first, then positions), making charts, using deductive reasoning, and eliminating possibilities can serve as powerful tools for quickly working out Mastermind codes. Try solving this one.

Game 2
Guess 1: G B B B
One peg is the right color and in the right position.
Guess 2: O B W W
Nothing is correct.
Guess 3: Y R Y R
One peg is the right color and in the right position; one more is the right color.
Guess 4: Y B Y Y
One peg is the right color but in the wrong position.
Guess 5: O B O R
One peg is the right color and in the right position. You should now have enough clues to solve the puzzle.

Mitchell also presented a number of strategies applicable specifically to Mastermind. "You can glean a great deal of information from patterns," he asserted. Certain peg positions and color combinations often offer important clues.

Spotting particular game patterns can help you solve codes. Consider the following pair of guesses.

Guess 1: B O R G
Two pegs are the right color.
Guess 2: B O R W
Three pegs are the right color.

The only difference between the rows is the color in the fourth position. Yet, according to the feedback from the codemaker, a third peg now has the right color. From that change, you can readily deduce that W is the correct color and G is incorrect.

In general, Mitchell noted, if two rows differ by only one color and the number of feedback pegs changes from one row to the next, then it must be the one changed color that caused the increase (or decrease) in response.

Try out your pattern-searching strategies on the following game.

Game 3
Guess 1: G B R B
One peg is the right color but in the wrong position.
Guess 2: B G B Y
One peg is the right color and in the right position; one more is the right color.
Guess 3: R Y B R
One peg is the right color but in the wrong position.
Guess 4: O W G Y
One peg is the right color and in the right position; two more are the right color.
Guess 5: O G Y O
Three pegs are the right color and in the right position.

There's much more in Mitchell's book, all the way up to formal proofs. Indeed, it's amazing how much mathematical activity you can get out of playing Mastermind over and over again. And if the standard version isn't challenging enough, you can always increase the number of colors and the number of slots.

One more thing. The book's many sample game situations give you something to work on when no one happens to be around to set the secret codes for you. Or you can try an online version of Mastermind.

Originally posted October 11, 1999

ANSWERS
Game 1: B R O O
Game 2: G Y G R
Game 3: O G Y G

No comments: