Price of Locality in Permutation Mastermind:
Are TikTok Influencers Chaotic Enough?
Abstract
In the permutation Mastermind game, the goal is to uncover a secret permutation by making a series of guesses which must also be permutations of , and receiving as feedback after guess the number of positions for which . While the existing literature on permutation Mastermind suggests strategies in which and might be widely different permutations, a resurgence in popularity of this game as a TikTok trend shows that humans (or at least TikTok influencers) use strategies in which consecutive guesses are very similar. For example, it is common to see players attempt one transposition at a time and slowly see their score increase. Motivated by these observations, we study the theoretical impact of two forms of locality in permutation Mastermind strategies: -local strategies, in which any two consecutive guesses differ in at most positions, and the even more restrictive class of -local strategies, in which consecutive guesses differ in a window of length at most . We show that, in broad terms, the optimal number of guesses for local strategies is quadratic, and thus much worse than the guesses that suffice for non-local strategies. We also show NP-hardness of the satisfiability version for -local strategies, whereas in the -local variant the problem admits a randomized polynomial-time algorithm.
Keywords and phrases:
Permutation Mastermind, Locality, NP-hard2012 ACM Subject Classification:
Mathematics of computing CombinatoricsFunding:
This work is supported by the National Science Foundation under grant DMS-2434625.Editor:
John IaconoSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
The classical game of Mastermind, and its many variations, have received significant attention from computer scientists and mathematicians since the 1970s [15, 4, 19, 12, 6, 1, 11, 17]. However, it is only in the last couple of years that the permutation black-peg Mastermind variant has reached internet virality through a TikTok challenge often named “bottle match challenge” or “color match challenge”. The goal of the challenge is to guess a secret permutation of colored bottles, based on guesses that also consist of permutations of an equivalent set of colored bottles. To each guess, a different player that we will call codemaker, responds with the number of positions for which the guess matches the secret permutation. In the TikTok trend, the secret permutation is hidden from the player under a table or a box, but visible to the viewer throughout the game (see Figure 1). Perhaps the success of the trend can be explained by paraphrasing filmmaker Alfred Hitchcock: suspense is not about a bomb exploding on scene, but rather about the audience watching people talk about trivial matters while a bomb ticks underneath their table.
After observing a variety of TikTok influencers play permutation Mastermind, a common aspect of their strategies came to my attention: they usually only permute a couple of bottles between guesses. In contrast, the best known upper bound for permutation Mastermind, which takes guesses for bottles, is based on guessing uniformly random permutations [17], and thus almost all bottles are permuted between guesses on average.111Recall that a uniformly random permutation has a single fixed point in expectation. My initial hypothesis was that these “local” strategies, which permute only a small number of bottles between guesses, are natural for humans since it might be easier to keep track of the information throughout the game. This is reminiscent, for instance, of the analysis of Mastermind with constant-sized memory, by Doerr and Winzen [5]. This paper aims to take the only reasonable course of action after TikTok has started to appropriate our well-studied game of Mastermind: to study a theoretical model of these local strategies and their implications both on the number of guesses required to win the game, and on its computational complexity.
1.1 Preliminaries
Before stating our main results, let us briefly formalize the problem at hand and present some of the best bounds known for the general case of permutation Mastermind.
Permutation Mastermind.
Let and be the symmetric group, or in other words, the set of permutations together with the composition operation. A secret code is a permutation chosen by the codemaker. In round , the codebreaker plays a guess and receives the black-peg score222The name comes from the original physical version of the game, in which black pegs were used to indicate the number of correct positions guessed.
An adaptive strategy is a function that maps the transcript to the next guess . A static (non-adaptive) strategy is a fixed list of guesses chosen in advance. In the adaptive setting, a guess wins the game for the codebreaker if . In the static (i.e., non-adaptive) setting, after the codebreaker announces their fixed list of guesses , the codemaker responds with the scores , after which the codebreaker gets to do one last guess to potentially win the game [9].
Locality notions and Cayley-Mastermind.
We consider two different forms of locality, defined next based on the notation for the set of indices in which two permutations differ. For any , we will say a strategy is -local if for every two consecutive guesses and made by the strategy in any transcript, we have . For a permutation , we call the set the support of .
A strategy is -local if for every two consecutive guesses and it holds that
Intuitively, this means there is some “window” such that differs from only within that window (i.e., ).
In the static case, we will assume that the last guess after receiving the scores is free of locality restrictions.
Our notions of locality are a particular case of playing Mastermind on a Cayley graph. Given a set of generators of , we can define the -Permutation-Mastermind game in which the codemaker chooses a secret vertex of the Cayley graph , then the codebreaker guesses an arbitrary starting vertex , and for , the codebreaker must guess a vertex adjacent in to . Equivalently, a vertex such that . Naturally, we can define in turn a -strategy for the standard permutation Mastermind as one that always plays according to the rules of the -Permutation-Mastermind game. For example, for any , we define as the set of all permutations in whose support has size at most . A strategy of permutation Mastermind is then said to be -local if its consecutive guesses differ in at most positions, or equivalently, if it plays on the Cayley graph . We purposely present this more general version of the definition to motivate a natural direction of future research: studying permutation Mastermind under other sets of generators.
Query complexities.
Let be the minimum such that there exists an adaptive strategy that determines within guesses in the worst case. Let be the analogous minimum for static strategies. For local versions, define: as the minimum worst-case number of guesses among adaptive/static strategies subject to the corresponding locality constraint ( or ). The main previous results that contextualize our work are summarized in Table 1.
1.2 Our Contributions
We prove the following results.
Theorem 1.
For the -local setting, we have
Theorem 2.
In the -local static setting, we have
Theorem 3.
For the -local setting, we have .
Our lower bounds are graph-theoretic in nature, and interestingly, they are based on giving the codebreaker even more advantage in order to simplify the analysis; we consider generous codemakers that reveal exactly which of the permuted positions of some guess is correct. A similar setting was studied by Li and Zhu [18], who considered the more general case of Mastermind with “Wordle” feedback. Our upper bounds for Theorem 1 and Theorem 2 are based on simulating the best known upper bounds without locality restrictions. The upper bound of Theorem 3, in turn, uses a similar strategy to that of [18].
Finally, we prove a hardness result, showing that processing the feedback received is not easy even if each guess was a single transposition from the previous one. It was first proved by de Bondt [3] that standard Mastermind, which includes the white-peg score, is NP-hard. Independently, Stuckman and Zhang [21] provided a different proof. Then, Goodrich [11] extended the result to only black-peg score feedback. We take these results further by proving hardness in the permutation variant, and even on the -local setting. In contrast, for the -local setting, we show the problem can be solved in randomized polynomial time, leveraging an algorithm for perfect matchings with parity constraints from Geelen and Kapadia [8].
Theorem 4.
The satisfiability problem for permutation Mastermind in the -local setting is -hard. In other words, given a transcript , where each pair of consecutive guesses differs in at most 3 positions, it is -hard to decide whether there exists a secret such that for every . In turn, for the -local setting there is a randomized polynomial-time algorithm.
2 Adaptive Lower Bound on -local Strategies
This section is devoted to proving the lower bound of Theorem 1. The main object we will handle in the proof is a bipartite graph representing the potential secrets compatible with the information seen thus far. It will be convenient for this proof to think of as a string of length over an alphabet , so that positions of are just integers in but the elements of have a different type, . This way, we think of as a function from to . To any , we associate a bipartite graph , where a pair if and only if . Note that these graphs are perfect matchings.
Recall that is the black-peg score of a guess. Let be the set of all guesses such that .
Then, given a sequence of guesses , to which the codemaker has answered , and some , we say is compatible with if for .
Definition 5 (Graph of possible secrets).
Given a sequence of guesses , to which the codemaker has answered , we define the graph of possible secrets
As a degenerate case, is the complete bipartite graph between and .
The following observation is immediate, but will be useful to translate our problem into a graph-theoretic one.
Observation 6.
Given a sequence of guesses , to which the codemaker has answered , the codebreaker can be certain of the secret permutation if and only if has a unique perfect matching.
We now prove that, for a graph to have a unique perfect matching, it needs to be missing a significant number of edges. We will make use of the following folklore observation (illustrated in Figure 2):
Observation 7.
If a finite bipartite graph has minimum degree at least , it cannot have a unique perfect matching.
Proof.
If has no perfect matchings, the statement holds trivially. Thus, let be a perfect matching of . For each vertex , let denote its neighbor in the matching , and denote one neighbor of via an edge not in , chosen arbitrarily, which must exist since has degree at least . Now let be any vertex, and construct a walk by
Since is finite, some vertex appears twice in this walk. Let with , chosen so that all intermediate vertices are distinct. Then the subwalk forms a simple alternating cycle , which necessarily has even length. Consider the matching . For vertices not in , agrees with . Each vertex of is incident to exactly one edge of and one edge of , so it is matched by exactly one edge in . Thus is a perfect matching. Since contains edges not in , we have , contradicting the uniqueness of .
We now use Observation 7 to show a much stronger condition implied by having a unique perfect matching.
Lemma 8.
Let be a balanced bipartite graph with . Then, if has a unique perfect matching, .
Proof.
Let be the maximum number of edges of a balanced bipartite graph with vertices that has a unique perfect matching. We trivially have . For , we claim that . Before proving the claim, let us see that it is enough to conclude, since then, using induction we will have
Now, to prove the claim, we consider an arbitrary balanced bipartite graph on vertices with a unique perfect matching and such that . Let be the minimum degree in , and note that : since has a perfect matching we have , and by Observation 7 we have . Let be a vertex of degree , and its only neighbor. It must be the case that and belong to opposite sides of the bipartition, and thus if we consider the graph resulting from by removing vertices and , we get a balanced bipartite graph on vertices. Moreover, must belong to the (unique) perfect matching of , and therefore any perfect matching of would extend (by adding ) to a perfect matching of , and thus must also have a unique perfect matching. Therefore, . On the other hand,
We thus have
concluding the claim.
The tightness of Lemma 8 is witnessed by half graphs (see Figure 3), which include the edge if and only if . The uniqueness of a perfect matching in can be easily seen by induction, noting that vertex has degree one, and upon removing together with its neighbor , we are left exactly with , for which the inductive hypothesis applies.
2.1 Generous and Supergenerous Codemakers
Perhaps paradoxically, I found that proving lower bounds on permutation Mastermind with locality becomes easier if we give more power to the codebreaker, but in a way that makes the game simpler.
Namely, while a normal codemaker will give as feedback (i.e., the number of correctly guessed positions), we will consider a generous codemaker that gives the set as feedback. Note that, any strategy against a generous codemaker can be used against a standard codemaker without any loss, since from the codebreaker can compute .
In the original form of the game, each guess can be described as well by , the set of newly guessed edges. Except for the first guess, which tests edges, each guess tests at most edges in the setting. We will define a supergenerous codemaker as one that allows the codebreaker to guess individual edges one by one, giving generous feedback to each (i.e., revealing whether it is correct or not), but only accounting 1 guess per each individual-edge guesses. Naturally, if we prove a lower bound of individual-edge guesses against a supergenerous codemaker, then guesses are necessary against a standard codemaker.
2.2 Finishing the proof of Theorem 1’s lower bound
Lemma 9.
Let . Then, any deterministic adaptive strategy in the -local model requires guesses.
Proof.
We consider an adversarial supergenerous codemaker. The adversary will keep a graph , with , and upon receiving a guess for , it will answer yes if and only if belongs to all perfect matchings of . If it answers no, the adversary sets , and otherwise . Let be the set of all perfect matchings compatible with the answers given until time (including to guess ), and the set of all perfect matchings of . Then, by construction, we have that the adversary says yes to an edge if and only if for every .
Let be the set of all perfect matchings in . We will prove by induction that for every . For it holds trivially since both sets include all possible matchings. For , we consider two cases. First, if the adversary said no to guess , we have
and similarly, But by the inductive hypothesis we then have
On the other hand, if the adversary answered yes, we have by definition
| (Since the answer to was yes) | ||||
| (inductive hypothesis) | ||||
| (Since as the answer to was yes) |
We have thus proved that . Now, observe that by definition the codebreaker can only win when . But this implies , and by Lemma 8, this implies . But , from where we get
Therefore, the lower bound we get against a standard codemaker is at least
3 Lower Bound for the Static Variant
This section is devoted to the static version of permutation Mastermind with locality considerations. Recall that in this variant, the codebreaker must reveal a fixed sequence of guesses upfront, subject to the locality constraints, after which they will receive the black-peg feedback , and then finally make their final guess that must equal the secret permutation in order to win. The final guess is not subject to the locality restrictions.
The main ingredient of our lower bound is a classic result on extremal graph theory (see [22] for a modern presentation).
Theorem 10 ([14, 7]).
The maximum number of edges an -vertex graph can have without containing a is . Moreover, the maximum number of edges on a -free bipartite graph with vertices on each side is .
For this proof we will consider a simpler graph than in Section 2. Let be the bipartite graph where an edge is present if and only if no guess with has . Intuitively, corresponds to the untested matching edges up to time . Now, we will prove the relevance of -subgraphs. For this, let us say the static part of a strategy, , is sufficient, if for every secret , the only permutation compatible with the transcript is exactly . Naturally, the static part of any correct static strategy must be sufficient.
Lemma 11.
If is the static part of a correct static strategy, then is -free.
Proof.
Suppose for a contradiction that contains a consisting of the four edges
An illustration with a concrete example is depicted in Figure 4. Now, let be an arbitrary permutation such that and . From we define now the permutation by
In other words, is the matching obtained from via the alternating -cycle corresponding to the . Now, note that for any guess we have . Indeed, let and we prove by cases that if and only if :
-
If , then , and thus the claim holds.
-
If , then by construction we have as well as . But by definition of , we have . Therefore neither nor .
We thus have that for any guess , which implies both and are compatible with transcript , and thus is not sufficient.
Our lower bound is now a direct consequence of the previous lemma and the quantitative bounds on -free graphs.
Theorem 12.
For any we have
Proof.
Consider a correct strategy whose static part is . Note that before the first guess we have . The first guess tests edges, so , and after this special first guess the -locality condition implies for that
Therefore, . Now, since the static strategy is correct, we must have that is -free, and by Theorem 10 it must hold that Combining our inequalities, we have , from where , thus concluding the proof.
4 Diameter-Based Upper Bounds
In this section we prove the upper bounds for Theorem 1 and Theorem 2 by a rather direct simulation adaptation of the upper bounds of [17, 20]. In a nutshell, it suffices to show that we can pay to simulate regular guesses in the -local model. This idea generalizes to the following lemma.
Lemma 13.
Let be a set of generators for . Let denote the minimum number of guesses for a correct static strategy for the -Permutation-Mastermind game, and denote the minimum number of guesses in the worst case of an adaptive strategy. Then,
Proof.
We write the proof in terms of the static setting, but the adaptive one is identical. Let be a correct static strategy for the standard permutation Mastermind. Then, for each , write as a word over that minimizes . Then, by definition of the diameter . Now, construct the guess sequence
which is -Permutation-Mastermind strategy, and has size at most
We now prove a tight bound on the diameter of the Cayley graph corresponding to the -local setting.
Lemma 14.
Fix . Recall that is the set of permutations with support on at most elements. Then,
Proof.
Since is a Cayley graph and thus vertex transitive, it suffices to upper bound the distance between the identity permutation , and an arbitrary permutation .
Let be the support of , and let . Letting , we will prove by induction on that the stronger statement holds for any .
If , then and the bound holds. Otherwise , since is not possible. If , then , so , which agrees with the bound.
Assume now that . We will construct such that , and then invoke the inductive hypothesis.
Write as a product of disjoint cycles , and for each nontrivial cycle fix any cyclic ordering of its elements. By listing the elements of the nontrivial cycles in these cyclic orders (cycle by cycle), we obtain a sequence that enumerates with the property that for every , either , or else is the last element of its cycle (in which case is the first element of that same cycle and hence appears earlier in the list).
Let be the first elements of the previously obtained sequence, and observe that for every we have : indeed, if with , then either , or is the last element of its cycle and is the first element of that cycle, which also lies in .
Since is injective and , the set has size , so there is a unique element . Define by
By construction, only moves elements of , so . Moreover, for every we have so fixes all elements of . Since , these are indices that were moved by , and thus
Now, since and , we have
where the second inequality is the inductive hypothesis. This completes the induction.
Finally, since , we conclude that for every , we have and hence .
Proposition 15 (Upper bounds).
In the static -local model,
and in the adaptive -local model,
Proof.
5 Window Locality
In this section we consider the -local model. Intuitively, one would expect this more restrictive model to require many more guesses than the -local model. However, perhaps surprisingly, showing a good separation result is one of the questions we will leave open.
Let us start by remarking that diameter-based upper bounds, as in Section 4, cannot help us here, since in the -local model the diameter is as we show next.
Proposition 16.
Let be the set of permutations for which there exists an index such that for . Then,
Proof.
Consider the permutation , and let us prove that . For this, define the function by Note that , whereas
where the last equality can be seen by splitting the sum into two parts depending on whether the argument of the absolute value is positive or not.
To conclude, it suffices to show that, for any and , we have
| (1) |
Indeed, if , we could write as with and for all . But then we would have
which contradicts the fact that . We now prove (1). let be the interval from the definition of in which is potentially different from , and then observe that
But by definition of , we have that , and thus for . Therefore,
which proves (1) and thus concludes the proof.
Naturally, the diameter of the Cayley graph yields a lower bound on , but in this case such a bound is weaker than the one we get from the trivial inequality , combined with Theorem 1.
While using the diameter bound between guesses of a normal permutation Mastermind strategy would only yield an upper bound, we show that is always a valid upper bound for , and it holds already for . Since the diameter lower bound immediately shows , we focus on proving the upper bound of Theorem 3.
Proposition 17.
We have .
Proof.
First, let us assume the codemaker is generous, in the sense of Section 2, and thus reveals after every guess which of the changed positions is correct. We will then show how to get rid of this assumption with only a constant overhead.
We will now use the following “conveyor belt” strategy (see Algorithm 1): take the sequence of adjacent transpositions and repeat it times. For example for , this strategy guesses:
The nice property of this sequence of adjacent transpositions is that each element goes through every position, and thus, since the codemaker is generous, after this sequence of guesses, the codebreaker will know exactly what the secret permutation is.
More formally, for each value (line 3 of Algorithm 1), the first element of right after line 4 is , and it will be at position after exactly guesses. Thus, the exact position of must be revealed by the generous codemaker on that pass.
After having identified the position of each element, the codebreaker knows the target permutation, and can reach the secret permutation through a shortest path. Using the well-known identity , the codebreaker will reach the secret permutation in guesses.
Now, it only remains to show how to simulate the generous codemaker with only a constant factor overhead. For this, consider for example that for the last guess was and we now want to guess but receiving generous feedback. We will do the sequence of guesses: Intuitively, the scores received throughout this sequence will uniquely determine the “generous” feedback for the guess . More in general, we will replace each transposition by guesses that traverse the possible permutations of (or in case ). The fact that going through the permutations allows us to determine if any of the cycled elements should go into one of the positions of the cycle can be checked via finite computation. Indeed, the following Python3 code is enough:
To conclude the proof, we observe that the strategy is indeed static.
6 The Complexity of Locality
This section is dedicated to proving Theorem 4. We will start by proving NP-hardness of the permutation variant without considering the locality restriction, and then show how a modification of the proof yields hardness even in the -local setting. We will conclude the section by proving that in the -local setting there is a randomized polynomial algorithm.
Our reduction is from Monotone-1-in-3-SAT, where the input is a 3-CNF formula with only positive literals, and the goal is to decide if some assignment of its variables assigns exactly 1 literal per clause to true. A more formal description is presented below. Interestingly, the first proof of NP-completeness of Mastermind was a reduction from 1-in-3-SAT (non-monotone) [3], but our construction is different.
PROBLEM : Monotone-1-in-3-SAT INPUT : A 3-CNF formula , over variables , with each clause , and each . OUTPUT : Yes, if there is an assignment such that for every clause we have . No otherwise.
Now we present the Permutation-Mastermind-SAT problem.
PROBLEM : Permutation-Mastermind-SAT INPUT : A sequence of permutations , and a sequence of black-peg scores . OUTPUT : Yes, if there is some permutation such that for each . No otherwise.
Theorem 19.
Permutation-Mastermind-SAT is -complete.
Proof.
Membership is trivial, since it suffices to guess . For hardness, we reduce from Monotone-1-in-3-SAT. Let , over variables , be an input instance of Monotone-1-in-3-SAT. Then, we set , and we will construct an instance of Permutation-Mastermind-SAT over .
The first guess will be simply the identity , and the score is . This enforces that the secret permutation holds for each . In order to define the next guesses we will need some notation. For each , let us define the block . Intuitively, the first part of our construction will enforce that in the secret permutation , we have , meaning that the secret permutation is only permuting within blocks of 3 elements.
Using notation for concatenation, we can define the identity permutation as . Now, for each and , we define the permutation
For example, if , and , then
Let be an arbitrary enumeration of . We now introduce new guesses, corresponding to the permutations for and . The score for each of them will be .
Claim 20.
Any permutation compatible with the scores for the guesses made thus far satisfies
Proof.
Assume the condition fails for some . Then, some element of belongs to a block for . Let us assume .333Otherwise we implicitly do . Then, for some it must be the case that guess gets score at least , which contradicts the compatibility assumption with the received scores which are all .
We therefore have that the secret permutation must be of the form
where each is a permutation with no fixed points. In particular, the only two possibilities in are and . Intuitively, we will have if variable should be assigned to true in , and if it should be assigned to false.
Concretely, for each clause with , we create a permutation
The score given to each of these guesses will be .
We are now ready to prove the correctness of the reduction. Let with , and be the sequence of guesses and scores of our construction.
Claim 21.
If is a Yes-instance for Monotone-1-in-3-SAT, then is a Yes-instance for Permutation-Mastermind-SAT.
Proof.
Let be the satisfying assignment for which witnesses its membership in Monotone-1-in-3-SAT. Then, let be the permutation where
It suffices to check that all scores on are as constructed. First, since both and have no fixed points, we indeed have . Let us write for the -th block of a permutation .
Then, we claim that for every and . Indeed, for , we have , whereas is either or , and in either case . For , we also have that is either or , whereas , and thus .
Finally, for each clause , we claim that . Indeed, by assumption, there is exactly one variable such that , so , and thus and by construction , so . If the other variables of are and , then for any we have , whereas is either or , and in either case . For we have by assumption, and thus , whereas , and again .
To complete our proof, we prove the other direction of the reduction.
Claim 22.
If is a Yes-instance for Permutation-Mastermind-SAT, then is a Yes-instance for Monotone-1-in-3-SAT.
Proof.
Assume there is some compatible with the transcript . Then, based on Claim 20, we have for each that for some . Because and , all the must have no fixed points. But on the only two permutations without fixed points are exactly and . Therefore, for each . Now, define the assignment by
Now, let be an arbitrary clause in . Then, since guess got score , we have that
| (2) |
However, for each , we have , in which case or , in which case . Thus, the only way to satisfy Equation 2 is that for exactly one , , and thus satisfies exactly one variable of .
Since the reduction clearly takes polynomial time, this completes the proof.
We will now show that the construction above can be adapted so that each pair of consecutive guesses differs in a fixed number of positions. The main difficulty is that, while the sequence of guesses from the proof of Theorem 19 could be “interpolated” by a series of transpositions between each and , the reduction needs to construct scores for these intermediate guesses as well, and it must do so in such a way that does not require knowing what a satisfying assignment (if there is any) looks like.
PROBLEM : -Local-PM-SAT INPUT : A sequence of permutations , where each , for some permutation of support size at most , and a sequence of black-peg scores . OUTPUT : Yes, if there is some permutation such that for each . No otherwise.
Theorem 23.
3-Local-PM-SAT is -complete.
Proof.
Membership is again trivial since it suffices to guess . For hardness, the proof is very similar to that of Theorem 19, also via a reduction from Monotone-1-in-3-SAT, but we will need some non-trivial modifications. Once again, if the input instance has variables, we will construct an instance of 3-Local-PM-SAT over for . The first guess will again be the identity with a score of , implying the secret permutation must not have any fixed points. Then, similarly to the proof of Theorem 19, we will construct guesses and scores enforcing that
| (3) |
This part can be done in fact under the stronger -local restriction. It suffices to take every pair of indices such that (i.e., and belong to different blocks of size ), and guess the permutation defined by
The associated score of each guess will be , and after each such guess, we will guess again the identity permutation with a score of , before making the next guess . This stage makes guesses, and indeed guarantees Equation 3 since any position in is guessed in every position outside of and receives a score of . Now, we turn our attention to the clause guesses. Let be a clause in , with . Our goal is to make the guess
However, we will have to “walk” to such a guess by permutations of support size at most . Let us show an example for , with the clause . For ease of notation, we will identify the identity permutation with , and highlight in blue the permuted elements of each guess.
Naturally, this sequence of permutations can be inverted to obtain back the identity. More formally, let us introduce notation for the permutation that applies to positions , and similarly, we define . Then, the sequence of guesses corresponding to a clause is:
-
1.
,
-
2.
,
-
3.
,
-
4.
,
-
5.
,
-
6.
,
-
7.
,
-
8.
,
-
9.
.
Their corresponding scores are: . Consecutive “clause gadgets” can be chained by appending the inverse walk back to between clauses, with the corresponding scores. We now make the main claim for the correctness of the reduction.
Claim 24.
A permutation is compatible with the scores constructed thus far if and only if we have
where each is either or , and for each clause , exactly one of equals .
Proof.
The first part is direct from Equation 3 and the fact that the identity guess has a score of , since and are the only permutations in without fixed points.
The second part can be checked mechanically. It suffices to consider clause without loss of generality, and for each of the possibilities for , observe that the only ones that give the scores are those with exactly one . This is shown in Table 2, and concludes the proof of the claim.
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | |
| 3 | 2 | 2 | 1 | 2 | 1 | 1 | 0 | |
| 6 | 4 | 4 | 2 | 4 | 2 | 2 | 0 | |
| 9 | 6 | 6 | 3 | 6 | 3 | 3 | 0 |
Having proven Claim 24, we will proceed to prove the correctness of the reduction.
Claim 25.
If is a Yes-instance for Monotone-1-in-3-SAT, then the sequence of guesses and scores constructed above is a Yes-instance for 3-Local-PM-SAT.
Proof.
Let be the satisfying assignment for which witnesses its membership in Monotone-1-in-3-SAT. Then, let be the permutation
where
Then, by Claim 24 we have that is compatible with , thus proving it is a Yes-instance for 3-Local-PM-SAT.
Claim 26.
If is a Yes-instance for 3-Local-PM-SAT, then is a Yes-instance for Monotone-1-in-3-SAT.
Proof.
Directly by Claim 24 it suffices to take the assignment that assigns each to if , and to otherwise.
Since the reduction can clearly be constructed in polynomial time, we conclude the proof.
Finally, we show that 2-Local-PM-SAT can be solved in randomized polynomial time, by formulating it as a search over perfect matchings with parity constraints. In particular, we consider the following problem.
PROBLEM : -Dimensional Parity Perfect Matching INPUT : A , a weight function , a function , a constant , and a number . OUTPUT : A perfect matching of such that , and such that .
Theorem 27 ([8, Thm. 5.6]).
There is a randomized algorithm that solves the -Dimensional Parity Perfect Matching problem, over instances on vertices, in time , with probability of success .
Strictly speaking, the algorithm of Geelen and Kapadia [8] is intended for minimizing , but this is only done in step 3 of their evaluation algorithm, where the minimum exponent of the variable is considered; by considering the term including instead, from the same polynomial, we obtain the form of Theorem 27.
Theorem 28.
2-Local-PM-SAT is in , and in particular, can be solved in time with success probability .
Proof.
Let and be an instance of 2-Local-PM-SAT over . Then, as in Section 2, we identify a permutation with the perfect matching in the complete bipartite graph , and note that .
We can assume without loss of generality that the transcript contains no consecutive guesses being equal, i.e., , since otherwise we can remove the consecutive duplicates from the transcript without altering satisfiability. Because of the -locality restriction, for each there is a (unique) transposition such that . Let and and define the four edges
Then , and only these two positions can change their contribution to the black-peg score when passing from to . Let . Letting be the matching associated to a secret permutation compatible with the scores (if any exists), shows:
Consequently, we will construct an instance of perfect matching with the following constraint sets: a set of edges that must necessarily be present in the secret perfect matching , a set of edges that must necessarily not be present in the secret perfect matching , and a set of pairs of edges such that for every pair , exactly one of the edges in must be present in the secret perfect matching . These sets of constraints are constructed by Algorithm 2.
By the previous analysis, we have the following observation.
Observation 29.
There exists a secret permutation compatible with the transcript if and only if has a perfect matching such that:
-
1.
,
-
2.
,
-
3.
for every , ,
-
4.
for every pair of edges , .
We will now show how to decide the existence of such a matching by reducing to the -Dimensional Parity Perfect Matching problem. First, we define the edge weight function as follows:
Now, note that, for any perfect matching of , we have
from where (i) if , then , and (ii) if , then .
Therefore any perfect matching of satisfies conditions 1 and 2 of Observation 29 if and only if .
Now, let . Let be an arbitrary enumeration of , and an arbitrary enumeration of . For each , let denote the -th standard basis vector. We now define a label function by
| (4) |
We are now ready for the main claim that will prove the theorem. Let us write for the vector of all ones in .
Claim 30.
There exists a secret compatible with the transcript if and only if has a perfect matching such that and .
Proof.
We have shown above that a matching of satisfies conditions 1 and 2 of Observation 29 if and only if .
Now we show that satisfies conditions 3 and 4 if and only if . Let us use notation for the -th coordinate of a vector , and we will show that for . We consider two cases:
-
(Case 1: ). In this case, for a unique , so only the second sum of (4) is non-zero, so we have
from where if and only if (i.e., condition 3. holds for ).
-
(Case 2: ). In this case, only the first sum of (4) is non-zero, so we have
from where if and only if is odd. But since , the only possibility is . Thus, if and only if condition 4 holds for .
This concludes the proof.
Applying Theorem 27 to the instance , and then using Claim 30, we conclude the proof. The final runtime results from the fact that .
References
- [1] Peyman Afshani, Manindra Agrawal, Benjamin Doerr, Carola Doerr, Kasper Green Larsen, and Kurt Mehlhorn. The query complexity of a permutation-based variant of mastermind. Discrete Applied Mathematics, 260:28–50, 2019. doi:10.1016/J.DAM.2019.01.007.
- [2] Andreas Darmann and Janosch Döcker. On simplified NP-complete variants of Monotone 3 -Sat. Discrete Applied Mathematics, 292:45–58, 2021. doi:10.1016/j.dam.2020.12.010.
- [3] MC de Bondt. NP-completeness of master mind and minesweeper, 2004.
- [4] Benjamin Doerr, Carola Doerr, Reto Spöhel, and Henning Thomas. Playing mastermind with many colors. Journal of the ACM (JACM), 63(5):1–23, 2016. doi:10.1145/2987372.
- [5] Benjamin Doerr and Carola Winzen. Playing mastermind with constant-size memory, 2011. arXiv:1110.3619.
- [6] Mourad El Ouali and Volkmar Sauerland. The exact query complexity of yes-no permutation mastermind. Games, 11(2):19, 2020. doi:10.3390/G11020019.
- [7] Pál Erdős, Alfréd Rényi, and Vera T. Sós. On a problem of graph theory. Stud. Sci. Math. Hung., 1:215–235, 1966.
- [8] Jim Geelen and Rohan Kapadia. Computing girth and cogirth in perturbed graphic matroids. Combinatorica, 38(1):167–191, January 2017. doi:10.1007/s00493-016-3445-3.
- [9] Christian Glazik, Gerold Jäger, Jan Schiemann, and Anand Srivastav. Bounds for the static permutation mastermind game. Discrete Mathematics, 344(112253), 2021. doi:10.1016/j.disc.2020.112253.
- [10] E Mark Gold. Complexity of automaton identification from given data. Information and Control, 37(3):302–320, 1978. doi:10.1016/S0019-9958(78)90562-4.
- [11] Michael T Goodrich. On the algorithmic complexity of the mastermind game with black-peg results. Information Processing Letters, 109(13):675–678, 2009. doi:10.1016/J.IPL.2009.02.021.
- [12] Gerold Jäger and Marcin Peczarski. The number of pessimistic guesses in generalized mastermind. Information Processing Letters, 109(12):635–641, 2009. doi:10.1016/J.IPL.2009.02.016.
- [13] jasminandjulio. TikTok - Make Your Day — jasminandjulio. https://www.tiktok.com/@jasminandjulio/video/7333730349534727470. [Accessed 12-01-2026].
- [14] Thomas Kővári, Vera Sós, and Pál Turán. On a problem of K. Zarankiewicz. Colloquium Mathematicae, 3(1):50–57, 1954. URL: http://eudml.org/doc/210011.
- [15] Donald Ervin Knuth. The computer as master mind. Journal of Recreational Mathematics, 9:1–6, 1977.
- [16] Ker-I Ko and Shia-Chung Teng. On the number of queries necessary to identify a permutation. Journal of Algorithms, 7(4):449–462, 1986. doi:10.1016/0196-6774(86)90013-1.
- [17] Maxime Larcher, Anders Martinsson, and Angelika Steger. Solving static permutation mastermind using queries. The Electronic Journal of Combinatorics, 29(1), January 2022. doi:10.37236/10280.
- [18] Renyuan Li and Shenglong Zhu. Playing mastermind with wordle-like feedback. The American Mathematical Monthly, 131(5):390–399, February 2024. doi:10.1080/00029890.2024.2308489.
- [19] Anders Martinsson and Pascal Su. Mastermind with a linear number of queries. Combinatorics, Probability and Computing, 33(2):143–156, 2024. doi:10.1017/S0963548323000366.
- [20] Mourad El Ouali, Christian Glazik, Volkmar Sauerland, and Anand Srivastav. On the query complexity of black-peg ab-mastermind, 2016. arXiv:1611.05907.
- [21] Jeff Stuckman and Guo-Qiang Zhang. Mastermind is np-complete, 2005. arXiv:cs/0512049.
- [22] Yufei Zhao. Graph Theory and Additive Combinatorics: Exploring Structure and Randomness. Cambridge University Press, Cambridge, 2023. doi:10.1017/9781009310956.
