Abstract 1 Introduction 2 Adaptive Lower Bound on 𝒌-local Strategies 3 Lower Bound for the Static Variant 4 Diameter-Based Upper Bounds 5 Window Locality 6 The Complexity of Locality References

Price of Locality in Permutation Mastermind:
Are TikTok Influencers Chaotic Enough?

Bernardo Subercaseaux ORCID Carnegie Mellon University, Pittburgh, PA, USA
Abstract

In the permutation Mastermind game, the goal is to uncover a secret permutation σ:[n][n] by making a series of guesses π1,,πT which must also be permutations of [n], and receiving as feedback after guess πt the number of positions i for which σ(i)=πt(i). While the existing literature on permutation Mastermind suggests strategies in which πt and πt+1 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: k-local strategies, in which any two consecutive guesses differ in at most k positions, and the even more restrictive class of wk-local strategies, in which consecutive guesses differ in a window of length at most k. We show that, in broad terms, the optimal number of guesses for local strategies is quadratic, and thus much worse than the O(nlgn) guesses that suffice for non-local strategies. We also show NP-hardness of the satisfiability version for 3-local strategies, whereas in the 2-local variant the problem admits a randomized polynomial-time algorithm.

Keywords and phrases:
Permutation Mastermind, Locality, NP-hard
Copyright and License:
[Uncaptioned image] © Bernardo Subercaseaux; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Mathematics of computing Combinatorics
Related Version:
Full Version: https://arxiv.org/abs/2601.19161
Funding:
This work is supported by the National Science Foundation under grant DMS-2434625.
Editor:
John Iacono

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.

Figure 1: Illustration of a game of permutation Mastermind for n=6 from TikTok [13]. Guesses are labeled by treating the secret permutation as the identity σ:=(1 2 3 4 5 6).

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 O(nlgn) guesses for n 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 n2 and Sn be the symmetric group, or in other words, the set of permutations [n][n] together with the composition operation. A secret code is a permutation σSn chosen by the codemaker. In round t, the codebreaker plays a guess πtSn 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.

b(πt,σ):=|{i[n]:πt(i)=σ(i)}|.

An adaptive strategy is a function that maps the transcript ((π1,b1),,(πt1,bt1)) to the next guess πtSn. A static (non-adaptive) strategy is a fixed list of guesses (π1,,πT) chosen in advance. In the adaptive setting, a guess πt wins the game for the codebreaker if πt=σ. In the static (i.e., non-adaptive) setting, after the codebreaker announces their fixed list of guesses (π1,,πT), the codemaker responds with the scores b(π1,σ),,b(πT,σ), 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 D(π,σ):={i[n]:π(i)σ(i)} for the set of indices in which two permutations differ. For any k2, we will say a strategy is k-local if for every two consecutive guesses πt and πt+1 made by the strategy in any transcript, we have |D(πt,πt+1)|k. For a permutation πSn, we call the set D(π,idn):={i[n]:π(i)i} the support of π.

A strategy is wk-local if for every two consecutive guesses πt and πt+1 it holds that

max(D(πt,πt+1))min(D(πt,πt+1))k1.

Intuitively, this means there is some “window” I:={i,i+1,,i+k1} such that πt+1 differs from πt only within that window (i.e., D(πt,πt+1)I).

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 Sn, we can define the Γ-Permutation-Mastermind game in which the codemaker chooses a secret vertex of the Cayley graph Cay(Sn,Γ), then the codebreaker guesses an arbitrary starting vertex v0, and for t1, the codebreaker must guess a vertex vt adjacent in Cay(Sn,Γ) to vt1. Equivalently, a vertex vt such that vt11vtΓ. 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 k2, we define Ln(k) as the set of all permutations in Sn whose support has size at most k. A strategy of permutation Mastermind is then said to be k-local if its consecutive guesses differ in at most k positions, or equivalently, if it plays on the Cayley graph Cay(Sn,Ln(k)). 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 A(n) be the minimum T such that there exists an adaptive strategy that determines σ within T guesses in the worst case. Let S(n) be the analogous minimum for static strategies. For local versions, define: A(n,k),Aw(n,k),S(n,k),Sw(n,k) as the minimum worst-case number of guesses among adaptive/static strategies subject to the corresponding locality constraint (k or wk). The main previous results that contextualize our work are summarized in Table 1.

Table 1: Best-known asymptotic query complexities for permutation Mastermind.
Function Lower bound Upper bound
A(n) Ω(n) [16, 20] O(nlgn) [16, 20]
S(n) Ω(nlgn) [9] O(nlgn) [17]

1.2 Our Contributions

We prove the following results.

Theorem 1.

For the k-local setting, we have n23n2kA(n,k)n2lgnk(1+o(1)).

Theorem 2.

In the k-local static setting, we have

n2(1+o(1))n3/2kS(n,k)28nlgnn1k1.
Theorem 3.

For the wk-local setting, we have Sw(n,2)=Θ(n2).

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 3-local setting. In contrast, for the 2-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 3-local setting is NP-hard. In other words, given a transcript ((π1,b1),,(πt,bt)), where each pair of consecutive guesses differs in at most 3 positions, it is NP-hard to decide whether there exists a secret σ such that b(πi,σ)=bi for every 1it. In turn, for the 2-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 n over an alphabet Σ:={s1,,sn}, so that positions of σ are just integers in [n]:={1,,n} but the elements of σ have a different type, Σ. This way, we think of σ as a function from [n] to Σ. To any σ:[n]Σ, we associate a bipartite graph Bσ:=([n]Σ,E), where a pair {i,sj}E if and only if σ(i)=sj. Note that these graphs Bσ are perfect matchings.

Recall that b(π,σ)=|{i[n]:π(i)=σ(i)}| is the black-peg score of a guess. Let b1(k,σ) be the set of all guesses π:[n]Σ such that b(π,σ)=k.

Then, given a sequence of guesses Π=(π1,,πt), to which the codemaker has answered B:=(b1,,bt), and some π:[n]Σ, we say π is compatible with (Π,B) if b(πi,π)=bi for 1it.

Definition 5 (Graph of possible secrets).

Given a sequence of guesses Π=(π1,,πt), to which the codemaker has answered B:=(b1,,bt), we define the graph of possible secrets

Pt:=σ is compatible with (Π,B)Bσ.

As a degenerate case, P0 is the complete bipartite graph between [n] 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 Π=(π1,,πt), to which the codemaker has answered B:=(b1,,bt), the codebreaker can be certain of the secret permutation σ if and only if Pt has a unique perfect matching.

We now prove that, for a graph Pt 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):

Figure 2: Illustration of the proof for Observation 7. Edges of the original matching M are colored red, and edges in E(C)M are dashed blue. Gray edges are not part of the matchings, and the resulting matching M is colored green.
Observation 7.

If a finite bipartite graph B has minimum degree at least 2, it cannot have a unique perfect matching.

Proof.

If B has no perfect matchings, the statement holds trivially. Thus, let M be a perfect matching of B. For each vertex u, let M(u) denote its neighbor in the matching M, and D(u) denote one neighbor of u via an edge not in M, chosen arbitrarily, which must exist since u has degree at least 2. Now let u0 be any vertex, and construct a walk u0,u1, by

ui:={M(ui1)if i is oddD(ui1)otherwise.

Since B is finite, some vertex appears twice in this walk. Let uj=uk with j<k, chosen so that all intermediate vertices are distinct. Then the subwalk uj,uj+1,,uk forms a simple alternating cycle C, which necessarily has even length. Consider the matching M=ME(C). For vertices not in C, M agrees with M. Each vertex of C is incident to exactly one edge of M and one edge of E(C)M, so it is matched by exactly one edge in M. Thus M is a perfect matching. Since C contains edges not in M, we have MM, contradicting the uniqueness of M.

We now use Observation 7 to show a much stronger condition implied by having a unique perfect matching.

Lemma 8.

Let B=(XY,E) be a balanced bipartite graph with n:=|X|=|Y|. Then, if B has a unique perfect matching, |E|(n+12).

Proof.

Let f(n) be the maximum number of edges of a balanced bipartite graph with 2n vertices that has a unique perfect matching. We trivially have f(1)=1. For n2, we claim that f(n)f(n1)+n. Before proving the claim, let us see that it is enough to conclude, since then, using induction we will have

f(n)(n2)+n=n(n1)2+n=(n+12).

Now, to prove the claim, we consider an arbitrary balanced bipartite graph Bn on 2n vertices with a unique perfect matching and such that |E(Bn)|=f(n). Let δ be the minimum degree in Bn, and note that δ=1: since Bn has a perfect matching we have δ1, and by Observation 7 we have δ<2. Let uV(Bn) be a vertex of degree 1, and v its only neighbor. It must be the case that u and v belong to opposite sides of the bipartition, and thus if we consider the graph resulting from Bn by removing vertices u and v, we get a balanced bipartite graph B on 2(n1) vertices. Moreover, {u,v} must belong to the (unique) perfect matching of Bn, and therefore any perfect matching of B would extend (by adding {u,v}) to a perfect matching of Bn, and thus B must also have a unique perfect matching. Therefore, |E(B)|f(n1). On the other hand,

|E(B)|=|E(Bn)|degBn(v)(degBn(u)1)=|E(Bn)|degBn(v)|E(Bn)|n.

We thus have

f(n)=|E(Bn)||E(B)|+nf(n1)+n,

concluding the claim.

The tightness of Lemma 8 is witnessed by half graphs Hn (see Figure 3), which include the edge {i,sj} if and only if ij. The uniqueness of a perfect matching in Hn can be easily seen by induction, noting that vertex n has degree one, and upon removing n together with its neighbor sn, we are left exactly with Hn1, for which the inductive hypothesis applies.

Figure 3: The half graph H5, with (62)=15 edges. Its only perfect matching is highlighted in orange.

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 |BπBσ| as feedback (i.e., the number of correctly guessed positions), we will consider a generous codemaker that gives the set BπBσ as feedback. Note that, any strategy against a generous codemaker can be used against a standard codemaker without any loss, since from BπBσ the codebreaker can compute |BπBσ|.

In the original form of the game, each guess πt can be described as well by Et:=BπtBπt1, the set of newly guessed edges. Except for the first guess, which tests n edges, each guess πt tests at most k edges in the k 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 k individual-edge guesses. Naturally, if we prove a lower bound of t individual-edge guesses against a supergenerous codemaker, then (tn)/k guesses are necessary against a standard codemaker.

2.2 Finishing the proof of Theorem 1’s lower bound

Lemma 9.

Let k2. Then, any deterministic adaptive strategy in the k-local model requires n23n2k guesses.

Proof.

We consider an adversarial supergenerous codemaker. The adversary will keep a graph Gt, with G0:=Kn,n, and upon receiving a guess et for t1, it will answer yes if and only if et belongs to all perfect matchings of Gt1. If it answers no, the adversary sets GtGt1et, and otherwise GtGt1. Let 𝒮t be the set of all perfect matchings compatible with the answers given until time t (including to guess et), and 𝒮0=PM(Kn,n) the set of all perfect matchings of Kn,n. Then, by construction, we have that the adversary says yes to an edge et if and only if etM for every M𝒮t1.

Let PM(Gt) be the set of all perfect matchings in Gt. We will prove by induction that 𝒮t=PM(Gt) for every t0. For t=0 it holds trivially since both sets include all possible matchings. For t1, we consider two cases. First, if the adversary said no to guess et, we have

PM(Gt)=PM(Gt1){MPM(Gt1):etM},

and similarly, 𝒮t=𝒮t1{M𝒮t1:etM}. But by the inductive hypothesis we then have

𝒮t=PM(Gt1){MPM(Gt1):etM}=PM(Gt).

On the other hand, if the adversary answered yes, we have by definition

𝒮t =𝒮t1{M:M𝒮t1 and etM}
=𝒮t1=𝒮t1 (Since the answer to et was yes)
=PM(Gt1) (inductive hypothesis)
=PM(Gt). (Since Gt=Gt1 as the answer to et was yes)

We have thus proved that 𝒮t=PM(Gt). Now, observe that by definition the codebreaker can only win when |𝒮t|=1. But this implies |PM(Gt)|=1, and by Lemma 8, this implies |E(Gt)|(n+12). But |E(Gt)||E(G0)|t, from where we get

t|E(G0)||E(Gt)|=n2|E(Gt)|n2(n+12)=(n2).

Therefore, the lower bound we get against a standard codemaker is at least

tnk(n2)nk=n23n2k.

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 π1,,πT upfront, subject to the locality constraints, after which they will receive the black-peg feedback b1,,bT, 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 n-vertex graph can have without containing a K2,2 is (12+o(1))n3/2. Moreover, the maximum number of edges on a K2,2-free bipartite graph with n vertices on each side is (1+o(1))n3/2.

For this proof we will consider a simpler graph than in Section 2. Let Ut:=([n]×Σ,Et) be the bipartite graph where an edge {i,sj} is present if and only if no guess πr with rt has πr(i)=sj. Intuitively, Ut corresponds to the untested matching edges up to time t. Now, we will prove the relevance of K2,2-subgraphs. For this, let us say the static part of a strategy, π1,,πT, is sufficient, if for every secret σ, the only permutation compatible with the transcript ((π1,b(π1,σ)),,(πT,b(πT,σ))) is exactly σ. Naturally, the static part of any correct static strategy must be sufficient.

Figure 4: Illustration of the obstacle introduced by a K2,2 for uniquely determining σ. On the left, tested edges are colored light gray, while untested edges are colored black, except for those forming a K2,2 which are highlighted.
Lemma 11.

If π1,,πT is the static part of a correct static strategy, then UT is K2,2-free.

Proof.

Suppose for a contradiction that UT contains a K2,2 consisting of the four edges

{i,sx},{i,sy},{j,sx},{j,sy}.

An illustration with a concrete example is depicted in Figure 4. Now, let σ be an arbitrary permutation such that σ(i)=sx and σ(j)=sy. From σ we define now the permutation σ by

σ(k)={syif k=isxif k=jσ(k)otherwise.

In other words, σ is the matching obtained from σ via the alternating 4-cycle corresponding to the K2,2. Now, note that for any guess πt we have b(πt,σ)=b(πt,σ). Indeed, let k[n] and we prove by cases that σ(k)=πt(k) if and only if σ(k)=πt(k):

  • If k{i,j}, then σ(k)=σ(k), and thus the claim holds.

  • If k{i,j}, then by construction we have σ(k){sx,sy} as well as σ(k){sx,sy}. But by definition of UT, we have πt(k){sx,sy}. Therefore neither σ(k)=πt(k) nor σ(k)=πt(k).

We thus have that b(πt,σ)=b(πt,σ) for any guess πt, which implies both σ and σ are compatible with transcript ((π1,b(π1,σ)),,(πT,b(πT,σ))), and thus π1,,πT is not sufficient.

Our lower bound is now a direct consequence of the previous lemma and the quantitative bounds on K2,2-free graphs.

Theorem 12.

For any k2, we have S(n,k)n2(1+o(1))n3/2k.

Proof.

Consider a correct strategy whose static part is π1,,πT. Note that before the first guess we have |E(U0)|=n2. The first guess tests n edges, so |E(U1)|=n2n, and after this special first guess the k-locality condition implies for 2tT that

|E(Ut)||E(Ut1)|k.

Therefore, |E(UT)||E(U1)|kT=n2nkT. Now, since the static strategy is correct, we must have that UT is K2,2-free, and by Theorem 10 it must hold that |E(UT)|(1+o(1))n3/2. Combining our inequalities, we have (1+o(1))n3/2n2nkT, from where Tn2(1+o(1))n3/2k, 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 O(nlgn) upper bounds of [17, 20]. In a nutshell, it suffices to show that we can pay O(n/k) to simulate regular guesses in the k-local model. This idea generalizes to the following lemma.

Lemma 13.

Let Γ be a set of generators for Sn. Let SΓ(n) denote the minimum number of guesses for a correct static strategy for the Γ-Permutation-Mastermind game, and AΓ(n) denote the minimum number of guesses in the worst case of an adaptive strategy. Then,

SΓ(n)S(n)diam(Cay(Sn,Γ))andAΓ(n)A(n)diam(Cay(Sn,Γ))

Proof.

We write the proof in terms of the static setting, but the adaptive one is identical. Let π1,,πS(n) be a correct static strategy for the standard permutation Mastermind. Then, for each 1iS(n), write (πi1)1πi as a word ωi:=γ1(i)γri(i) over Γ that minimizes ri. Then, by definition of the diameter ridiam(Cay(Sn,Γ)). Now, construct the guess sequence

πΓ:=π1γ1(2)γr2(2)γ1(3)γr3(3)γ1(S(n))γrS(n)(S(n)),

which is Γ-Permutation-Mastermind strategy, and has size at most

1+i=2S(n)ri1+(S(n)1)diam(Cay(Sn,Γ))S(n)diam(Cay(Sn,Γ)).

We now prove a tight bound on the diameter of the Cayley graph corresponding to the k-local setting.

Lemma 14.

Fix k2. Recall that Ln(k) is the set of permutations with support on at most k elements. Then,

diam(Cay(Sn,Ln(k)))n1k1.

Proof.

Since Cay(Sn,Ln(k)) is a Cayley graph and thus vertex transitive, it suffices to upper bound the distance between the identity permutation idn, and an arbitrary permutation π.

Let M:=D(π,idn)={i[n]:π(i)i} be the support of π, and let m:=|M|. Letting dist:=distCay(Sn,Ln(k)), we will prove by induction on m that the stronger statement dist(id,π)m1k1 holds for any π.

If m=0, then π=idn and the bound holds. Otherwise m2, since m=1 is not possible. If mk, then πLn(k), so dist(idn,π)=1, which agrees with the bound.

Assume now that m>k. We will construct γLn(k) such that |D(γ1π,id)|m(k1), and then invoke the inductive hypothesis.

Write π as a product of disjoint cycles C1,,Cr, and for each nontrivial cycle Ci 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 v1,,vm that enumerates M with the property that for every 1j<m, either π(vj)=vj+1, or else vj is the last element of its cycle (in which case π(vj) is the first element of that same cycle and hence appears earlier in the list).

Let T:={v1,,vk} be the first k elements of the previously obtained sequence, and observe that for every xT{vk} we have π(x)T: indeed, if x=vj with j<k, then either π(x)=vj+1T, or x is the last element of its cycle and π(x) is the first element of that cycle, which also lies in T.

Since π is injective and π(T{vk})T, the set π(T{vk}) has size k1, so there is a unique element yTπ(T{vk}). Define γSn by

γ(x)={π(x)if xT{vk},yif x=vk,xotherwise.

By construction, γ only moves elements of T, so γLn(k). Moreover, for every xT{vk} we have (γ1π)(x)=γ1(π(x))=γ1(γ(x))=x, so γ1π fixes all elements of T{vk}. Since TM, these are k1 indices that were moved by π, and thus |D(γ1π,idn)|m(k1).

Now, since π=γ(γ1π) and γLn(k), we have

dist(idn,π)1+dist(idn,γ1π)1+(m(k1))1k1=m1k1,

where the second inequality is the inductive hypothesis. This completes the induction.

Finally, since mn, we conclude that for every πSn, we have dist(idn,π)n1k1, and hence diam(Cay(Sn,Ln(k)))n1k1.

Proposition 15 (Upper bounds).

In the static k-local model,

S(n,k)28nlgnn1k1,

and in the adaptive k-local model,

A(n,k)n2lgnk(1+o(1)).

Proof.

Larcher, Martinsson, and Steger proved that S(n)28nlgn [17], and thus combining Lemma 13 and Lemma 14 directly yields the first result.

On the other hand, El Ouali et al. [20] proved that A(n)(n3)lgn+52n1. Again, combining Lemma 13 and Lemma 14 yields the result.

5 Window Locality

In this section we consider the wk-local model. Intuitively, one would expect this more restrictive model to require many more guesses than the k-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 wk-local model the diameter is Ω(n2/k2) as we show next.

Proposition 16.

Let Wk be the set of permutations ωSn for which there exists an index i such that ω(j)=j for j{i,i+1,,i+k1}. Then,

diam(Cay(Sn,Wk))n2/2k(k1)12(nk)2.

Proof.

Consider the permutation π:in+1i, and let us prove that dist(π,idn)n2/2k(k1). For this, define the function δ:Sn by δ(π):=i=1n|π(i)i|. Note that δ(idn)=0, whereas

δ(π)=i=1n|n+1ii|=i=1n|n+12i|=n22,

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 πSn and ωWk, we have

δ(ωπ)δ(π)k(k1). (1)

Indeed, if dist(π,idn)<n2/2k(k1), we could write π as ω1ω2ωtidn with t<n2/2k(k1) and ωiWk for all i. But then we would have

δ(π)=i=1tδ(ωiω1idn)δ(ωi+1ω1idn)tk(k1)<n2/2,

which contradicts the fact that δ(π)=n2/2. We now prove (1). let Iω be the interval {i,,i+k1} from the definition of Wk in which ω is potentially different from idn, and then observe that

δ(ωπ) =i=1n|ω(π(i))i|
=i:π(i)Iω|π(i)i|+i:π(i)Iω|ω(π(i))i|
=i:π(i)Iω|π(i)i|+i:π(i)Iω|(ω(π(i))π(i))+(π(i)i)|
i:π(i)Iω|π(i)i|+i:π(i)Iω|ω(π(i))π(i)|+i:π(i)Iω|π(i)i|
=δ(π)+i:π(i)Iω|ω(π(i))π(i)|.

But by definition of Wk, we have that ω(Iω)=Iω, and thus |ω(j)j|k1 for jIω. Therefore,

δ(ωπ)δ(π)+i:π(i)Iω(k1)=δ(π)+k(k1),

which proves (1) and thus concludes the proof.

Naturally, the diameter of the Cayley graph yields a lower bound on Aw(n,k), but in this case such a bound is weaker than the one we get from the trivial inequality A(n,k)Aw(n,k), combined with Theorem 1.

While using the diameter bound between guesses of a normal permutation Mastermind strategy would only yield an O(n3lgnk2) upper bound, we show that O(n2) is always a valid upper bound for Sw(n,k), and it holds already for k=2. Since the diameter lower bound immediately shows Sw(n,2)=Ω(n2), we focus on proving the upper bound of Theorem 3.

Proposition 17.

We have Sw(n,2)=O(n2).

Proof.

First, let us assume the codemaker is generous, in the sense of Section 2, and thus reveals after every guess which of the k=2 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 n1 adjacent transpositions (1 2),(2 3),,(n1n) and repeat it n times. For example for n=4, this strategy guesses:

1. (1 2 3 4) 6. (3 4 2 1)
2. (2 1 3 4) 7. (3 4 1 2)
3. (2 3 1 4) 8. (4 3 1 2)
4. (2 3 4 1) 9. (4 1 3 2)
5. (3 2 4 1) 10. (4 1 2 3)

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.

Algorithm 1 ConveyorBelt(n).

More formally, for each value 1mn (line 3 of Algorithm 1), the first element of π right after line 4 is m, and it will be at position 2jn after exactly j1 guesses. Thus, the exact position of m 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 diam(Sn,W2)=(n2), the codebreaker will reach the secret permutation in O(n2) 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 n=3 the last guess was (1 2 3) and we now want to guess (2 1 3) but receiving generous feedback. We will do the sequence of guesses: (1 2 3)(1 3 2)(3 1 2)(3 2 1)(2 3 1)(2 1 3). Intuitively, the scores received throughout this sequence will uniquely determine the “generous” feedback for the guess (2 1 3). More in general, we will replace each transposition (ii+1) by 6 guesses that traverse the 6 possible permutations of {i,i+1,i+2} (or {i1,i,i+1} in case i=n1). The fact that going through the 6 permutations allows us to determine if any of the 3 cycled elements should go into one of the 3 positions of the cycle can be checked via finite computation. Indeed, the following Python3 code is enough:

1import itertools
2
3possible_masks = list(set(itertools.permutations([0,0,1,2,3], 3)))
4guesses = list(itertools.permutations([1,2,3]))
5
6results = {}
7for pm in possible_masks:
8 results[pm] = []
9 for g in guesses:
10 results[pm].append(sum(1 for m, g in zip(pm, g) if m == g))
11
12for pm1, pm2 in itertools.combinations(possible_masks, 2):
13 assert results[pm1] != results[pm2]

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 3-local setting. We will conclude the section by proving that in the 2-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 φ:=i=1mCi, over variables x1,,xn, with each clause Ci:=(x1(i)x2(i)x3(i)), and each xj(i){x1,,xn}. OUTPUT : Yes, if there is an assignment τ:{x1,,xn}{0,1} such that for every clause Ci we have τ(x1(i))+τ(x2(i))+τ(x3(i))=1. No otherwise.

Theorem 18 ([10], see [2]).

Monotone-1-in-3-SAT is NP-complete.

Now we present the Permutation-Mastermind-SAT problem.

PROBLEM : Permutation-Mastermind-SAT INPUT : A sequence of permutations π1,,πTSn, and a sequence of black-peg scores (b1,,bT){0,,n}. OUTPUT : Yes, if there is some permutation σSn such that b(πt,σ)=bt for each 1tT. No otherwise.

Theorem 19.

Permutation-Mastermind-SAT is NP-complete.

Proof.

Membership is trivial, since it suffices to guess σSn. For hardness, we reduce from Monotone-1-in-3-SAT. Let φ:=i=1mCi, over variables x1,,xn, be an input instance of Monotone-1-in-3-SAT. Then, we set N=3n, and we will construct an instance of Permutation-Mastermind-SAT over SN.

The first guess will be simply the identity π1:=idN, and the score is b1:=0. This enforces that the secret permutation σ holds σ(i)i for each 1iN. In order to define the next guesses we will need some notation. For each 1in, let us define the block Bi:=(3i2,3i1,3i). Intuitively, the first part of our construction will enforce that in the secret permutation σ=(s1s2sN), we have {s3i2,s3i1,s3i}={3i2,3i1,3i}, meaning that the secret permutation is only permuting within blocks of 3 elements.

Using notation for concatenation, we can define the identity permutation idNSN as B1B2Bn. Now, for each 1i<jn and σS3, we define the permutation

γi,j,σ:=B1Bi1σ(Bj)Bj1σ(Bi)Bn.

For example, if n=4, and σ=(1 3 2), then

γ1,3,σ=σ(B3)B2σ(B1)B4=(7 9 8 4 5 6 1 3 2 10 11 12).

Let σ1,,σ6 be an arbitrary enumeration of S3. We now introduce 6(n2) new guesses, corresponding to the permutations γi,j,σk for 1i<jn and 1k6. The score for each of them will be 0.

Claim 20.

Any permutation σ compatible with the scores for the 1+6(n2) guesses made thus far satisfies

1in,{σ(3i2),σ(3i1),σ(3i)}={3i2,3i1,3i}.

Proof.

Assume the condition fails for some 1in. Then, some element of {σ(3i2),σ(3i1),σ(3i)} belongs to a block Bj for ji. Let us assume i<j.333Otherwise we implicitly do i:=min(i,j),j=max(i,j). Then, for some k it must be the case that guess γi,j,σk gets score at least 1, which contradicts the compatibility assumption with the received scores which are all 0.

We therefore have that the secret permutation σ must be of the form

σ(1)(B1)σ(2)(B2)σ(n)(Bn),

where each σ(i) is a permutation with no fixed points. In particular, the only two possibilities in S3 are α:=(2 3 1) and β:=(3 1 2). Intuitively, we will have σ(i)=α if variable xi should be assigned to true in φ, and β if it should be assigned to false.

Concretely, for each clause C:=(xaxbxc) with a<b<c, we create a permutation

πC:=B1Ba1α(Ba)Ba+1α(Bb)α(Bc)Bn.

The score given to each of these guesses will be 3.

We are now ready to prove the correctness of the reduction. Let π1,,πT with T=1+6(n2)+m, and b1,,bT be the sequence of guesses and scores of our construction.

Claim 21.

If φ is a Yes-instance for Monotone-1-in-3-SAT, then (π1,,πT),(b1,,bT) 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 σ(1)(B1)σ(2)(B2)σ(n)(Bn) where

σ(i)={αif τ(xi)=1βotherwise.

It suffices to check that all scores on σ are as constructed. First, since both α and β have no fixed points, we indeed have b(idN,σ)=0. Let us write σ[i]:=(σ(3i2),σ(3i1),σ(3i)) for the i-th block of a permutation σ.

Then, we claim that b(γi,j,σ,σ)=0 for every 1i<jn and σS3. Indeed, for k{1,,n}{i,j}, we have γi,j,σ[k]=Bk, whereas σ[k] is either α(Bk) or β(Bk), and in either case b(γi,j,σ[k],σ[k])=0. For k{i,j}, we also have that σ[k] is either α(Bk) or β(Bk), whereas γi,j,σ[k]=σ(B{i,j}{k}), and thus b(γi,j,σ[k],σ[k])=0.

Finally, for each clause C, we claim that b(πC,σ)=3. Indeed, by assumption, there is exactly one variable xiC such that τ(xi)=1, so σ(i)=α, and thus πC[i]=α(Bi) and by construction σ[i]=α(Bi), so b(πC[i],σ[i])=3. If the other variables of C are xj and xk, then for any {i,j,k} we have πC[]=B, whereas σ[] is either α(B) or β(B), and in either case b(πC[],σ[])=0. For {j,k} we have τ(x)=0 by assumption, and thus σ[]=β(B), whereas πC[]=α(B), and again b(πC[],σ[])=0.

To complete our proof, we prove the other direction of the reduction.

Claim 22.

If (π1,,πT),(b1,,bT) 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 (π1,,πT),(b1,,bT). Then, based on Claim 20, we have for each 1in that σ[i]=σ(i)(Bi) for some σ(i)S3. Because π1=idN and b1=0, all the σ(i) must have no fixed points. But on S3 the only two permutations without fixed points are exactly α:=(2 3 1) and β:=(3 1 2). Therefore, σ(i){α,β} for each 1in. Now, define the assignment τ:{x1,,xn}{0,1} by

τ(xi):={1 if σ(i)=α0 otherwise.

Now, let C:=(xaxbxc) be an arbitrary clause in φ. Then, since guess πC got score 3, we have that

b(α(Ba),σ[a])+b(α(Bb),σ[b])+b(α(Bc),σ[c])=3. (2)

However, for each g{a,b,c}, we have σ[g]=α(Bg), in which case b(α(Bg),σ[g])=3 or σ[g]=β(Bg), in which case b(α(Bg),σ[g])=0. Thus, the only way to satisfy Equation 2 is that for exactly one g{a,b,c}, σ(g)=α, and thus τ satisfies exactly one variable of C.

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 π1,,πT from the proof of Theorem 19 could be “interpolated” by a series of transpositions between each πt and πt+1, 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 : k-Local-PM-SAT INPUT : A sequence of permutations π1,,πTSn, where each πt+1:=πtωt+1, for some permutation ωt+1 of support size at most k, and a sequence of black-peg scores (b1,,bT){0,,n}. OUTPUT : Yes, if there is some permutation σSn such that b(πt,σ)=bt for each 1tT. No otherwise.

Theorem 23.

3-Local-PM-SAT is NP-complete.

Proof.

Membership is again trivial since it suffices to guess σSn. 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 n variables, we will construct an instance of 3-Local-PM-SAT over SN for N:=3n. The first guess will again be the identity idN with a score of 0, 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

1in,{σ(3i2),σ(3i1),σ(3i)}={3i2,3i1,3i}. (3)

This part can be done in fact under the stronger 2-local restriction. It suffices to take every pair of indices 1i<j3n such that i/3j/3 (i.e., i and j belong to different blocks of size 3), and guess the permutation δi,j defined by

δi,j(k)={kif k{i,j}iif k=jjif k=i.

The associated score of each guess δi,j will be 0, and after each such guess, we will guess again the identity permutation idN with a score of 0, before making the next guess δi,j. This stage makes O(n2) guesses, and indeed guarantees Equation 3 since any position in Bi:={3i2,3i1,3i} is guessed in every position outside of Bi and receives a score of 0. Now, we turn our attention to the clause guesses. Let C=(xixjxk) be a clause in φ, with i<j<k. Our goal is to make the guess

πC:=B1Bi1α(Bi)Bi+1α(Bj)α(Bk)Bn.

However, we will have to “walk” to such a guess by permutations of support size at most 3. Let us show an example for n=4, with the clause C=(x1x3x4). For ease of notation, we will identify the identity permutation with b1b2b12, and highlight in blue the permuted elements of each guess.

b1b2b3b4b5b6b7b8b9b10b11b12
b7b2b3b4b5b6b10b8b9b1b11b12
b7b8b3b4b5b6b10b11b9b1b2b12
b7b8b9b4b5b6b10b11b12b1b2b3
b8b9b7b4b5b6b10b11b12b1b2b3
b8b9b7b4b5b6b11b12b10b1b2b3
b8b9b7b4b5b6b11b12b10b2b3b1
b2b9b7b4b5b6b8b12b10b11b3b1
b2b3b7b4b5b6b8b9b10b11b12b1
b2b3b1b4b5b6b8b9b7b11b12b10

Naturally, this sequence of permutations can be inverted to obtain back the identity. More formally, let us introduce notation α(i,j,k) for the permutation that applies αS3 to positions i,j,k, and similarly, we define β(i,j,k). Then, the sequence of guesses corresponding to a clause C=(xixjxk) is:

  1. 1.

    α(3i2,3j2,3k2),

  2. 2.

    α(3i1,3j1,3k1),

  3. 3.

    α(3i,3j,3k),

  4. 4.

    α(3i2,3i1,3i),

  5. 5.

    α(3j2,3j1,3j),

  6. 6.

    α(3k2,3k1,3k),

  7. 7.

    β(3i2,3j2,3k2),

  8. 8.

    β(3i1,3j1,3k1),

  9. 9.

    β(3i,3j,3k).

Their corresponding scores are: (0,0,0,0,0,0,1,2,3). Consecutive “clause gadgets” can be chained by appending the inverse walk back to idN 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

σ=σ(1)(B1)σ(2)(B2)σ(n)(Bn)

where each σ(i) is either α:=(2 3 1) or β:=(3 1 2), and for each clause (xixjxk)φ, exactly one of σ(i),σ(j),σ(k) equals α.

Proof.

The first part is direct from Equation 3 and the fact that the identity guess idN has a score of 0, since α and β are the only permutations in S3 without fixed points.

The second part can be checked mechanically. It suffices to consider clause (x1x2x3) without loss of generality, and for each of the 8 possibilities for (σ(1),σ(2),σ(3)), observe that the only ones that give the scores (0,0,0,0,0,0,1,2,3) are those with exactly one α. This is shown in Table 2, and concludes the proof of the claim.

Table 2: Correctness of the sequence of clause guesses.
(σ(1),σ(2),σ(3)) (α,α,α) (α,α,β) (α,β,α) (α,β,β) (β,α,α) (β,α,β) (β,β,α) (β,β,β)
b1b2b3b4b5b6b7b8b9 0 0 0 0 0 0 0 0
b4b2b3b7b5b6b1b8b9 0 0 0 0 0 0 0 0
b4b5b3b7b8b6b1b2b9 0 0 0 0 0 0 0 0
b4b5b6b7b8b9b1b2b3 0 0 0 0 0 0 0 0
b5b6b4b7b8b9b1b2b3 0 0 0 0 0 0 0 0
b5b6b4b8b9b7b1b2b3 0 0 0 0 0 0 0 0
b5b6b4b8b9b7b2b3b1 0 0 0 0 0 0 0 0
b2b6b4b5b9b7b8b3b1 3 2 2 1 2 1 1 0
b2b3b4b5b6b7b8b9b1 6 4 4 2 4 2 2 0
b2b3b1b5b6b4b8b9b7 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 (π1,,πT),(b1,,bT) 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

σ(1)(B1)σ(2)(B2)σ(n)(Bn)

where

σ(i)={αif τ(xi)=1βotherwise.

Then, by Claim 24 we have that σ is compatible with (π1,,πT),(b1,,bT), thus proving it is a Yes-instance for 3-Local-PM-SAT.

Claim 26.

If (π1,,πT),(b1,,bT) 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 xi to 1 if σ(i)=α, and to 0 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 : t-Dimensional Parity Perfect Matching INPUT : A G=(V,E), a weight function w:E0, a function γ:E𝔽2t, a constant 𝐜𝔽2t, and a number r. OUTPUT : A perfect matching M of G such that w(M):=eMw(e)=r, and such that eMγ(e)=𝐜.

Theorem 27 (​​​[8, Thm. 5.6]).

There is a randomized algorithm that solves the t-Dimensional Parity Perfect Matching problem, over instances on n vertices, in time O(n6lg2nmaxeE(G)w(e)), with probability of success 1o(1).

Strictly speaking, the algorithm of Geelen and Kapadia [8] is intended for minimizing w(M), but this is only done in step 3 of their evaluation algorithm, where the minimum exponent of the variable z is considered; by considering the term including zr 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 O(n7lg2n) with success probability 1o(1).

Proof.

Let (π1,,πT) and (b1,,bT) be an instance of 2-Local-PM-SAT over Sn. Then, as in Section 2, we identify a permutation σSn with the perfect matching Bσ:={{i,σ(i)}:i[n]} in the complete bipartite graph Kn,n, and note that b(πt,σ)=|BπtBσ|.

We can assume without loss of generality that the transcript contains no consecutive guesses being equal, i.e., πt+1πt, since otherwise we can remove the consecutive duplicates from the transcript without altering satisfiability. Because of the 2-locality restriction, for each t[T1] there is a (unique) transposition ωt+1=(atbt) such that πt+1=πtωt+1. Let ut:=πt(at), and vt:=πt(bt), and define the four edges

et1:={at,ut},et2:={bt,vt},ft1:={at,vt},ft2:={bt,ut}.

Then BπtBπt+1={et1,et2,ft1,ft2}, and only these two positions can change their contribution to the black-peg score when passing from πt to πt+1. Let Δt:=bt+1bt. Letting Bσ be the matching associated to a secret permutation σ compatible with the scores (if any exists), shows:

Δt=2 {ft1,ft2}Bσ,
Δt=2 {et1,et2}Bσ,
Δt=1 |Bσ{ft1,ft2}|=1 and Bσ{et1,et2}=,
Δt=1 |Bσ{et1,et2}|=1 and Bσ{ft1,ft2}=,
Δt=0 Bσ{et1,et2,ft1,ft2}=.

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 Bσ, a set 𝒩 of edges that must necessarily not be present in the secret perfect matching Bσ, and a set 𝒞 of pairs of edges such that for every pair C𝒞, exactly one of the edges in C must be present in the secret perfect matching Bσ. These sets of constraints are constructed by Algorithm 2.

Algorithm 2 Construct Constraint Sets 𝒞,,𝒩.

By the previous analysis, we have the following observation.

Observation 29.

There exists a secret permutation σ compatible with the transcript (π1,,πT),(b1,,bT) if and only if Kn,n has a perfect matching M such that:

  1. 1.

    |MBπ1|=b1,

  2. 2.

    |M𝒩|=0,

  3. 3.

    for every e, |M{e}|=1,

  4. 4.

    for every pair of edges C𝒞, |MC|=1.

We will now show how to decide the existence of such a matching M by reducing to the t-Dimensional Parity Perfect Matching problem. First, we define the edge weight function w:E(Kn,n)0 as follows:

w(e):={nif e𝒩,1if e𝒩 and eBπ1,0otherwise.

Now, note that, for any perfect matching M of Kn,n, we have

w(M):=eMw(e)=n|M𝒩|+|(M𝒩)Bπ1|,

from where (i) if |M𝒩|>0, then w(M)n, and (ii) if |M𝒩|=0, then w(M)=n|MBπ1|.

Therefore any perfect matching M of Kn,n satisfies conditions 1 and 2 of Observation 29 if and only if w(M)=nb1.

Now, let t:=|𝒞|+||. Let C1,,Cm be an arbitrary enumeration of 𝒞, and e1,,ef an arbitrary enumeration of . For each 1it, let 𝐞i𝔽2t denote the i-th standard basis vector. We now define a label function γ:E(Kn,n)𝔽2t by

γ(e)=(i s.t. eCi𝐞i)+(i=1f𝐞i+m𝟙[e=ei]). (4)

We are now ready for the main claim that will prove the theorem. Let us write 𝟏 for the vector of all ones in 𝔽2t.

Claim 30.

There exists a secret σ compatible with the transcript (π1,,πT),(b1,,bT) if and only if Kn,n has a perfect matching M such that γ(M):=eMγ(e)=𝟏 and w(M)=nb1.

Proof.

We have shown above that a matching M of Kn,n satisfies conditions 1 and 2 of Observation 29 if and only if w(M)=nb1.

Now we show that M satisfies conditions 3 and 4 if and only if γ(M)=𝟏. Let us use notation 𝐯[j] for the j-th coordinate of a vector 𝐯, and we will show that γ(M)[j]=1 for j{1,,m+f}. We consider two cases:

  • (Case 1: j{m+𝟏,,m+f}). In this case, j=i+m for a unique i{1,,f}, so only the second sum of (4) is non-zero, so we have

    γ(M)[j]=eM𝟙[e=ei]=|M{ei}|mod2=|M{ei}|,

    from where γ(M)[j]=1 if and only if |M{ei}|=1 (i.e., condition 3. holds for ei).

  • (Case 2: j{𝟏,,m}). In this case, only the first sum of (4) is non-zero, so we have

    γ(M)[j]=eMi s.t. eCi𝟙i=j=eM𝟙eCj=|MCj|mod2,

    from where γ(M)[j]=1 if and only if |MCj| is odd. But since |Cj|=2, the only possibility is |MCj|=1. Thus, γ(M)[j]=1 if and only if condition 4 holds for Cj.

This concludes the proof.

Applying Theorem 27 to the instance (G,w,γ,𝟏), and then using Claim 30, we conclude the proof. The final runtime results from the fact that maxew(e)=n.

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 O(nlogn) 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.