TOPICS
Search

Mastermind


Mastermind is a simple two-player code-breaking board game invented in 1970 by Mordecai Meirowitz, an Israeli postmaster and telecommunications expert. It may have been inspired by moo, a program developed by J. M. Grochow at MIT in the late 1960s.

In the game, one player is the codemaker and the other is the codebreaker. The codemaker secretly selects a code consisting of an ordered sequence of four colors (c_1,c_2,c_3,c_4), each chosen from a set of six possible colors, with repetitions allowed. The codebreaker then tries to guess the code by repeatedly proposing a sequence of colors (g_1,g_2,g_3,g_4). After each guess, the codemaker tells the codebreaker two numbers (b,w): the number of correct colors in the correct positions (b) and the number of colors that are part of the code but not in the correct positions (w). For example, if the code is (1,2,3,3) and the codebreaker's guess is (3,2,4,3), then the codemaker's response would be (2,1), since the codebreaker has guessed the 2 and the second 3 correctly and in the correct positions, while having guessed the first three correctly but in the wrong position.

The codebreaker continues guessing until he guesses the code correctly or until he reaches a maximum allowable number of guesses without having correctly identified the secret code.

Interestingly, w can be computed as

 w=(sum_(i=1)^6min(c_i,g_i))-b,

where c_i is the number of times the color i is in the code and g_i is the number of times it is in the guess.

Knuth (1976-77) showed that the codebreaker can always succeed in five or fewer moves (i.e., knows the code after four guesses). His technique uses a greedy strategy that minimizes the number of remaining possibilities at each step, and requires 4.478 guesses on average, assuming equally likely code choice. Irving (1978-79) subsequently found a strategy with slightly smaller average length. Koyama and Lai (1993) described a strategy that minimizes the average number of guesses, requiring on average 4.340 guesses, although may require up to six in the worst case. A slight modification also described by Koyama and Lai (1993) increases the average to 4.341, but reduces the maximum number of guesses required to five.

The "static" problem of finding the minimum number of guesses the codebreaker can make all at once at the beginning of the game without waiting for the answers, and then upon receiving the answers, completely determine the code in the next "guess" (Chvatal 1983), can be solved with six initial guesses (Greenwell 1999-2000). One particular combination that allows the codebreaker to know the code after six guesses (and so require a seventh to reveal his knowledge of the solution) is (1, 2, 2, 1), (2, 3, 5, 4), (3, 3, 1, 1), (4, 5, 2, 4), (5, 6, 5, 6), (6, 6, 4, 3). It is not known if this number can be reduced to five (exhaustive checking would require 6^(5×4)=6^(20) approx 3.7×10^(15) computations), although it is believed not.

Swaszek (1999-2000) gives an analysis of practical strategies that do not require complicated record-keeping or use of a computer. Making a random guess from the set of remaining candidate code sequences gives a surprisingly short average game length of 4.638, while interpreting each guess as a number and using the next higher number consistent with the known information gives a game of average length 4.758.


Explore with Wolfram|Alpha

References

Bewersdorff, J. "Mastermind: Playing It Safe." Ch. 32 in Luck, Logic, & White Lies: The Mathematics of Games. Wellesley, MA: A K Peters, pp. 344-352, 2005.Bogomolny, A. and Greenwell, D. "Cut the Knot: Invitation to Mastermind." http://www.maa.org/editorial/knot/Mastermind.html.Chvatal, V. "Mastermind." Combinatorica 3, 325-329, 1983.Cole, T. "Investigations into the Master Mind Board Game: Break the Hidden Code." Feb. 5, 1999. http://www.tnelson.demon.co.uk/mastermind/.Erdős, P. and C. Rényi, C. "On Two Problems in Information Theory." Magyar Tud. Akad. Mat. Kut. Int. Közl. 8, 229-242, 1963.Flood, M. M. "Mastermind Strategy." J. Recr. Math. 18, 194-202, 1985-86.Flood, M. M. "Sequential Search Strategies with Mastermind Variants." J. Recr. Math. 20, 105-126 and 168-181, 1988.Greenwell, D. L. "Mastermind." J. Recr. Math. 30, 191-192, 1999-2000.Greenwell, D. L. "Mastermind." http://www.math.eku.edu/greenwell/MMTALK/.Greenwell, D. L. "Invitation to Mastermind." http://www.math.eku.edu/greenwell/MMTALK/MastermindTalkS5.html.Guy, R. "The Strong Law of Small Numbers." In The Lighter Side of Mathematics (Ed. R. K. Guy and R. E. Woodrow). Washington, DC: Math. Assoc. Amer., 1994.Irving, R. W. "Towards an Optimum Mastermind Strategy." J. Recr. Math. 11, 81-87, 1978-79.Knuth, D. E. "The Computer as a Master Mind." J. Recr. Math. 9, 1-6, 1976-77.Koyama, K. and Lai, T. W. "An Optimal Mastermind Strategy." J. Recr. Math. 25, 251-256, 1993.Mitchell, M. "MasterMind® Mathematics." Key Curriculum Press, 1999.Neuwirth, E. "Some Strategies for Mastermind." Z. für Operations Research 26, B257-B278, 1982.O'Geran, J. H.; Wynn, H. P.; and Zhigljavsky, A. A. "Mastermind as a Test-Bed for Search Algorithms." Chance 6, 31-37, 1993.Swaszek, P. F. "The Mastermind Novice." J. Recr. Math. 30, 193-198, 1999-2000.Temporel, A. "MSc Project: Stochastic Search Methods in Mastermind Game." http://www.cs.bris.ac.uk/~at1691/LittReview.html.Viaud, D. "Une stratégie générale pour jouer au Master-Mind." RAIRO Recherche opérationelle/Operations Research 21, 87-100, 1987.

Referenced on Wolfram|Alpha

Mastermind

Cite this as:

Weisstein, Eric W. "Mastermind." From MathWorld--A Wolfram Web Resource. https://mathworld.wolfram.com/Mastermind.html

Subject classifications