6
$\begingroup$

My father likes to tell a story about how he broke the system for a game event his school held. Specifically, he figured out a way to always at least break even on the Mastermind-like game, which would give you back the tickets you bet, and possibly more, as long as you found the answer by the last possible guess. He and a friend came up with a strategy such that they were guaranteed to solve the game by then.

However, beyond that it was a Mastermind variant, he does not remember any further details about the game. The minimal maximum number of guesses required for standard Mastermind is a solved problem: Donald Knuth came up with a 5-guess algorithm that is guaranteed to solve the puzzle when there are 6 different colors and the code is 4 colors long. (In Mastermind, the player attempts to guess a secret code consisting of 4 ordered elements which may be any of 6 different colors. After each guess, they get feedback consisting of how many colors are in the correct position, and how many colors are in the secret code but are in the wrong position. I am allowing duplicate colors but not "blanks" as a de facto extra color.)

My father doesn't think that his school's version of the game was exactly like the standard Mastermind. I am interested in the minimal maximum number of guesses when the parameters are varied. Surely there is a way to calculate this; I simply don't know how one would do the maths required.

Questions

  1. How does the minimal maximum number of guesses change when the number of possible colors changes? What if there are five colors? Seven colors? k colors? For this problem, hold the length of the secret code constant at 4.
  2. How does the minimal maximum number of guesses change when the length of the secret code changes? What if it is length three? Five? n? For this problem, hold the number of possible colors constant at 6.
  3. (Bonus) What is the minimal maximum number of guesses for k possible colors in a code of length n?
$\endgroup$

1 Answer 1

7
$\begingroup$

Unsurprisingly, the general question has also been addressed in the mathematical research literature.

Firstly, in the article V. Chvátal, "Mastermind", Combinatorica 3(3) (1983), pp. 325-329 (yes, the title of the paper is simply "Mastermind").

Mastermind is a game for two players, called S.F. and the P.G.O.M. In the beginning, S.F. creates a "mystery vector" $m = [ m_1 , m_2 , . . . , m_n]$ such that each $m_i$ is one of the "colors" $1, 2, ..., k$. The P.G.O.M. (who knows both $n$ and $k$) then proceeds to determine $m$ by asking a number of questions, which are answered by S.F. Each question $q$ is a vector $[q_1, q_2 ,..., q_n]$ such that each $q_i$ is one of the k colors; each answer consists of a pair of numbers $a(q, m), b(q, m)$ such that $a(q, m)$ is the number of subscripts $i$ with $q_i = m_i$ and $b(q, m)$ is the largest $a(q, \tilde{m})$ with $\tilde{m}$ running through all the permutations of $m$.

That just describes Mastermind in more mathematical language, with $k$ colours and a code of length $n$ (amusingly, the reverse of your original notation - that's two white pegs for you!) - the same notation as in the updated version of the OP.

In the commercial version that became popular a few years ago, $n = 4$ and $k = 6$ (with each answer represented by $a(q, m)$ black pins and $b(q, m ) - a ( q , m)$ white pins); Knuth [1] has shown that four questions suffice to determine $m$ in this case. The generalization to arbitrary $n$ and $k$ was suggested by Pierre Duchet, who asked for

(i) the smallest number $f ( n , k)$ such that the P.G.O.M. can determine any $m$ by asking $f(n, k)$ questions (waiting, as usual, for each answer before asking the next question), and

(ii) the smallest number $g(n, k)$ such that the P.G.O.M. can determine any $m$ by asking $g(n, k)$ questions at once (without waiting for the answers).

The number you want is $f(n,k)$, and this paper proves (Theorem 2) that:

If $n \leq k \leq n^2$ then $f(n, k) \leq 2n\log k + 4n$ [where "log" denotes the logarithm to base $2$].

Then, in the article W. Goddard, "Mastermind revisited", J. Combin. Math. Combin. Comput. 51 (2004), pp. 215-220, an exact formula is given for the case $n=2$ (only 2 positions, arbitrarily many colours): $$f(2,k)=\lfloor k/2\rfloor+2.$$

The article B. Doerr, C. Doerr, R. Spöhel, H. Thomas, "Playing mastermind with many colors", Journal of the ACM 63(5) (2016), pp. 1-23 improved Chvátal's bounds, and J. J. Merelo, "The game of MasterMind in 2020: an overview of literature" (link goes to PDF download) says that:

Mastermind is in 2020 still an open problem. Advances have been made in the theoretical arena, finding tight lower bounds to the number of queries that need to be made to find a solution, and in the heuristic arena, with finding how scoring functions for plausible solutions, or combinations of them, are able to find the solution faster by extracting an optimal amount of information from the oracle. [...] MasterMind is still a NP-complete problem, and spaces of solutions that have been researched are still very small; scaling of solutions is what we would expect it to be. [...] The search for a final solution is still open. It might be that there’s no single heuristic or combination of them that is able to find, in every move, the optimal combination for every possible code; this needs to be proved theoretically, however, Meanwhile, we will probably see in the next few years tighter bounds to the number of solutions, and faster solutions to problems that have double-digit number of “colors” and length.

This seems to be more or less the state of the art: upper bounds are known for the answer to your question, but no exact solution, neither for general $n$ nor for general $k$, except in some particularly simple cases like when there are only 2 pegs in the code.


How I found this answer:

  1. Start from the Wikipedia page linked in the OP, and go to the Knuth citation that was mentioned.
  2. Search for that paper on Google Scholar, where it has 244 citations.
  3. Check the list of articles that cite Knuth's (that's where further results beyond his would be found); that search yielded the Chvatal article.
  4. Search within citing articles (those citing Chvatal, this time) for the keyword "mastermind"; that search found the Goddard and Doerr et al. articles.
  5. Search within citing articles (those citing the 2016 article) for the keyword "mastermind" again; that search found the Merelo article, which is only a few years in the past.

Disclaimer: I saw this question in chat before the OP posted it, but I didn't start my research for answering it until it was already posted on the site, so as not to have any advantage over other potential answerers who might not be in chat.

$\endgroup$
4
  • $\begingroup$ +1. While this is probably a non-trivial mathematical theorem, the bound is at least for small values of $n$ and $k$ fairly lousy. In the classic mastermind this gives a bound of at most 36 questions whereas the best algorithm only takes 4 questions. $\endgroup$ Commented 11 hours ago
  • 1
    $\begingroup$ Heh, sorry about the notation swap. I'm going to edit the Q to change it to be consistent with the paper, that way you can discuss it easier :) $\endgroup$ Commented 11 hours ago
  • 1
    $\begingroup$ @bobble No need! It's very normal in maths for different people to use different notations for the same problem, and there's no particular reason that $n$ and $k$ should be one way round or the other in this case. $\endgroup$ Commented 11 hours ago
  • $\begingroup$ Graham Nelson wrote a paper on question 1. He found bounds between k/4 and k/4 + (small constant). $\endgroup$ Commented 3 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.