Optimal schemes for combinatorial query problems with integer feedback

,


Introduction
In 1960, Shapiro and Fine [19] posed the following question.Given n coins of unknown composition, where counterfeit coins weigh 9 grams and genuine coins weigh 10 grams, and an accurate spring scale (not a balance), how many weighings are required to isolate the counterfeit coins?For n ≥ 4, Shapiro and Fine observed that this can be done in fewer than n weighings, leading to the conjecture that, in general, o(n) weighings would suffice.
The problem of determining the optimal number of weighings became the subject of much independent research in the subsequent years.To summarize the findings, we distinguish between static solutions where the weighings are fixed before learning the answers, and adaptive solutions where each weighing may depend on answers to previous weighings.The minimum number of weighings required in static solutions is known to be where the lower bound is due to [8,17] and the upper bound is due to constructions given by Cantor and Mills [2] and Lindström [13,14].It was also shown by Erdős and Rényi [8] that a sequence of weighings chosen uniformly at random is likely to be able to distinguish between all configurations of counterfeit coins, albeit at a slightly higher number of (log 2 9 + o(1))n/ log 2 n weighings.See also the last section of their paper for an overview of further early works on this topic.While one would expect adaptive solutions to be more powerful, they are also harder to analyze.In either the static or adaptive case, the best known lower bounds are established by considering upper bounds on the amount of information that can be obtained in a single weighing, assuming the coins are independently either counterfeit or genuine, each with probability 1  2 .In the static case, the results of each weighing follow a binomial distribution, which is concentrated on √ n values, limiting the query entropy to roughly log 2 √ n = 1 2 log 2 n.However, in the adaptive case, the distribution of values returned from the weighings depends on how queries are generated.It is reasonable to think that optimal adaptive solutions would make use of this to make queries with higher information content, but to what extent this can be done remains unknown.The best known bounds on the minimum number T of queries needed in the adaptive case is where the upper bound is given by the static solutions, and the lower bound is obtained by bounding the query entropy by log 2 (n + 1), which is an upper bound on the entropy of any distribution on {0, 1, . . ., n}.This leaves a gap of a factor of 2 between the upper and lower bounds, which remains an important open question to this day.
To better understand the difference between static and adaptive solutions, it is useful to examine games where this contrast is more apparent.An example of such a game is the popular board game Mastermind, which was introduced commercially in the 1970s and formally described in 1983 by Chvátal [5].In Mastermind, one player, known as the Codemaker, creates a hidden pattern, or codeword, consisting of n entries, each of which can be one of k different colors.The other player, known as the Codebreaker, must try to guess this pattern by making a series of guesses.After each guess, the Codebreaker is awarded a certain number of black and white pegs, which indicate how close the guess is to the hidden pattern.Denoting the codeword x and a query q as elements of [k] n , the corresponding number of black pegs bp(x, q) := |{i ∈ [n] : x i = q i }| denotes the number of entries in the guess that match the corresponding entries in the hidden pattern 1 , while the number of white pegs wp(x, q) := max σ |{i ∈ [n] : x i = q σ(i) }| − bp(x, q), where σ goes over all permutations of [n], denotes the the number of entries that have the correct color but are in the wrong position.The game ends when the Codebreaker correctly guesses the hidden pattern.
We will below distinguish between black-peg Mastermind, where the Codebreaker is only told the number of black pegs corresponding to a query, and white-peg Mastermind, where the Codebreaker is also told the number of white pegs.
Since Mastermind with two colors and coin-weighing are essentially equivalent, see [18], Mastermind can be seen as a direct extension of coin-weighing.Analogously to the entropy bound for coin-weighing, we can derive lower bounds on the minimum number of adaptive queries T needed to recover any codeword.For black-peg Mastermind, this yields the bound n log 2 k log 2 (n + 1) ≤ T, while for white-peg Mastermind, this yields the bound We note that these bounds only differ by a factor of 2 + o(1).
For 2 ≤ k ≤ n 1−ε for any fixed ε > 0, solutions also behave similar to coin-weighing.Chvátal [5] showed that, for any k in this range, there exists a sequence of T = (2 + ε)n 1 + 2 log 2 k log 2 n − log 2 k static queries that uniquely determines any codeword, using only black-peg information.The proof uses the probabilistic method in a similar way to the proof by Erdős and Rényi [8] for coin-weighing.As this matches the general lower bounds up to constant factors, this means that, regardless of whether the queries are static or adaptive, and whether black-peg or white-peg Mastermind is considered, the minimum number of queries needed to recover any codeword is Θ ε (n log k/ log n).
Static black-peg Mastermind has been the focus of interest in its own right due to its equivalent formulation as the metric dimension or rigidity of Hamming graphs.By extending the coin-weighing solution of Lindström [13,14], Jiang and Polyanskii [12] showed that for any constant k ≥ 2, static guesses are optimal.For larger k, progress towards determining the length of optimal solutions has been slower.While the information-theoretic lower bound is linear in n whenever k ∼ n α for any constant α > 0, Chvátal states that the best upper bound he can offer for k ≥ n is O(n log n + k/n) in the white-peg setting and O(n log n + k) in the black-peg setting.Variations of these bounds with improved constants were proposed by Chen, Cunha and Homer [4], Goodrich [9], and Jäger and Peczarski [11].It can be noted that the terms k/n and k in the above bounds are necessary, which means that the solutions above are all optimal up to constants if k = Ω(n 2 log n) for white-peg Mastermind, or k = Ω(n log n) for black-peg Mastermind, but in particular for k = n this still leaves a gap of a factor Θ(log n).
It was first in 2016 that a paper by Doerr, Doerr, Spöhel and Thomas [7] managed to narrow this gap by showing that black-peg Mastermind with k = n colors can be solved in O(n log log n) queries.Finally, a recent work of the author together with Su [16] construct a randomized solutions for black-peg Mastermind with k = n colors using O(n) queries.This randomized solution has the property that, for any choice of the hidden codeword, Codebreaker will be able to uniquely identify it with probability 1 − e Ω(n) .This directly implies the existence of a randomized solution to black-peg Mastermind for any k ≥ 2 using O(n + k) queries.Moreover, combining this with results from Doerr, Doerr, Spöhel and Thomas, it follows that there exists a randomized solution to white-peg Mastermind using O(n + k/n) queries.Both of these results are best possible up to constant factors for k ≥ n ε for any ε > 0.
The difference between the cases where k ≤ n 1−ε and k = n in Mastermind can be explained by the concept of adaptivity.In the former case, optimal static solutions are up to constant factors as short as adaptive ones.However, for larger values of k, this is no longer true.In fact, Doerr, Doerr, Spöhel and Thomas showed that Θ(n log n) queries are optimal for static Mastermind with k = n colors.The reason for this is that in the static case, assuming the codeword is chosen uniformly at random, the number of black pegs returned from any query follows a Bin(n, 1/k) distribution, which has Θ ε (log n) entropy when k ≤ n 1−ε , but only Θ(1) when k = n.Adding white-peg information does not change this picture unless k is large.White pegs only carry information about the codeword up to permutations, which has negligible entropy compared to the full codeword when k = O(n).Therefore, in order to match the information-theoretic lower bound for Mastermind for k = n in either the black-peg or white-peg setting, one needs a precise understanding of the connection between adaptivity and information content of queries.
In this paper, we will take a more general approach to guessing games with integer feedback, such as coin-weighing and Mastermind.We will introduce a framework that allows us to express various guessing games, and adaptive solutions thereof in a common language.A virtue of the framework is that the information-theoretic speedup can be done using this abstract language, which makes it possible to separate the problem of making information-dense queries from problems relating to the specific game at hand.Our main technical results, Theorems 2.5 and 2.6, capture this by giving sufficient conditions for games to have short adaptive solutions.
As applications of our main results, we present a sequence of self-contained proofs of the existence of, up to constants, optimal deterministic adaptive solutions for various guessing games.In particular, using our results, we are able to determine the deterministic query complexity of Mastermind in both the black-peg and white-peg settings.
This matches the performance of the randomized solutions proposed by the author and Su [16].In the deterministic setting, these are the first known optimal solutions for any k ≥ n 1−o (1) .
It can further be remarked that the proofs of Theorems 1.1 and 1.2 are constructive and the corresponding solutions can be turned into efficient algorithms, including efficient decoding of the hidden codeword.In this respect, our results also improve upon the previous solutions found through the probabilistic method by Chvátal in the range 2 ≤ k ≤ n 1−ε .It is worth noting that the algorithmic problem of determining the hidden codeword from a general sequence of query-answer pairs is known to be NP-hard in both the black-peg and white-peg settings [20,9,21].Therefore, efficient recovery of the codeword is not immediate even in the cases where it is uniquely determined.
As part of deriving the solution for white-peg Mastermind, we further determine the query complexity of a new sparse version of the coin-weighing problem called sparse set query, where the player is faced with a collection of k coins and is told at most n are counterfeit, for some parameters k ≥ n.The problem is to determine which coins are counterfeit through few weighings, under the condition that at most n coins may be placed on the scale at a time.
Theorem 1.3.For any n ≤ k, the minimum number of adaptive queries needed to solve sparse set query is As a warm-up to proving these results, we will further derive up to constant factor optimal solutions to variations of the coin-weighing problem, and give a simplified proof for the existence of an O(n) solution to black-peg Mastermind with k = n in the case where the hidden codeword is required to be a permutation (but queries may still contain repeated colors).
In a sibling paper, we will further discuss how to use this framework to find optimal solutions for Permutation Mastermind, where k = n and guesses and codewords are both forbidden to contain repeated colors.
The remaining part of the paper will be structured as follows.In Section 2 we will introduce the abstract framework and the two technical main results, Theorems 2.5 and 2.6.These will be used to derive the aforementioned results.In Section 3 we will discuss applications of the main technical results, including Theorems 1.1, 1.2 and 1.3.Theorems 2.5 and 2.6 will be proven in Sections 4 and 5 respectively.Finally, in Section 6 we make some concluding remarks about our results.

Query games
A query game, A = (Q, F), is a pair of a set Q, and a non-empty set of functions F where f : Q → Z for all f ∈ F. We call the elements of Q queries and the elements of F codewords.For technical reasons, we always require that query games contain a zero-query 0 ∈ Q such that f (0) = 0 for all f ∈ F.
We can think of A = (Q, F) as a two-player game as follows.The first player, Codemaker, first chooses a codeword f ∈ F without telling the other player the choice.The second player, Codebreaker, must then determine f by asking a series of queries q(1), q(2), . . ., where, after each query q(t), Codemaker must respond with the value of f (q(t)).Throughout this paper, we will assume that the series of queries can be made adaptively, meaning that the choice of a query q(t) may depend on the answers f (q(1)), . . ., f (q(t − 1)) to all previous queries.The game is won after T steps if f is uniquely determined by Codemaker's responses to q(1), . . ., q(T ).That is, if, for every f ′ ∈ F \ {f }, there exists a 1 ≤ t ≤ T such that f ′ (q(t)) = f (q(t)).
We will use upper case letters A, B, C, . . . to denote query games, and bold upper case letters A, B, C, . . . to denote sets of query games.We will below treat two games as identical if they are isomorphic in the sense that they only differ by a relabelling of their queries.
Given two query games A = (Q A , F A ) and B = (Q B , F B ), we define the sum game A + B as the query game (Q A × Q B , F A × F B ), where we denote by q A + q B and f A + f B the pairs formed by (q A , q B ) ∈ Q A × Q B and (f A , f B ) ∈ F A × F B respectively, and where we define In other words, A + B is the game in which Codemaker picks a pair of codewords, one from each of A and B. For each query in the sum game, Codebreaker asks a query from A and a query from B simultaneously, and is told in return the sum of the responses.For sets of query games A and B, we define A + B := {A + B : A ∈ A, B ∈ B}.
We remark that the assumption that query games contain zero-queries ensures that we can query individual terms in a sum game A + B according to q A + 0 and 0 + q B respectively.
Example 2.1.A classical example of a query game is coin-weighing with n coins.We can define this formally as C n := (2 [n] , 2 [n] ), where we think of a codeword f ∈ 2 [n] as a function 2 [n] → Z by defining f (q) := |f ∩ q|.In other words, Codemaker presents a pile of n coins, and tasks Codebreaker to determine which coins are counterfeit.In each query, Codebreaker is allowed to pick an arbitrary subset of the coins and ask how many in the given set are fake.
It can be seen that this game, up to isomorphisms, satisfies where n • C 1 denotes the n-fold sum C 1 + • • • + C 1 , and, for any 1 ≤ k ≤ n − 1, we similarly have For a given game A = (Q A , F A ) a strategy is an adaptively constructed sequence of queries (q(t)) T t=1 .More precisely, for each 1 ≤ t ≤ T , the choice of query q(t) = q(t, f (q(1)), . . ., f (q(t − 1))) is allowed to depend on the responses of the preceding queries.We refer to T as the length of the strategy.A strategy is called a solution if it can uniquely determine any hidden codeword f ∈ F A .
Rather than attempting to construct solutions to query games directly, we often find it more effective to identify a sequence of reductions.To see how this works for query games, consider an instance of a query game A = (Q A , F A ), where Codebreaker uses a strategy (q(t)) T t=1 .Suppose that, given the corresponding sequence of answers f (q(1)), . . .f (q(T )), Codebreaker concludes that the hidden codeword f is contained in some subset F ′ ⊆ F A .At this point, we can consider A as reduced a query game B = (Q B , F B ), provided that each codeword f ′ ∈ F ′ can be uniquely identified with a codeword g ′ ∈ F B that is identical to f ′ up to relabelling and possibly discarding some elements of Q A .Thus any solution of B can be used from this point to solve A. We will refer to a strategy as a reduction from a query game A to a set of query games B, if for any possible answer sequence there is a query game B ∈ B with this property.We can state this more formally as follows.
Definition 2.2.Let A = (Q A , F A ) be a query game, and B a set of query games.We say that A can be reduced to B in T queries, denoted A T − → B, if there exists a strategy (q(t)) T t=1 of length T for A, with the following property.For any possible answer sequence a = (f (q(1)), . . ., f (q(T ))), there exists a choice of a game B = (Q B , F B ) ∈ B, depending only on a, and maps ϕ = ϕ a : When proving that a strategy satisfies the definition to be a reduction, it is often helpful to start by identifying the codewords of game A that are compatible with the answer sequence obtained so far using codewords of game B. Once these codewords are identified, we can then construct maps ϕ : for all identified pairs of codewords f ′ and g ′ , and for all q ∈ Q B .One can note that this contrasts the formal definition, where these notions are introduced in the opposite order.
The map ϕ first describes how to convert queries of B to queries of A. By property (i), we know that asking any query from Q B in the game A with hidden codeword f will return answers consistent with asking the same query in B with hidden codeword g := f •ϕ ∈ F B .By property (ii), once we determine this codeword g in B, the codeword of the original game is given by Φ(g).Thus, any not yet ruled out codeword f ′ of A is implicitly identified with the codeword f ′ • ϕ ∈ F B , where the map Φ ensures that no two codewords of A are paired with the same codeword in B.
Example 2.3.For any query game A = (Q A , F A ), any q ∈ Q A can be seen as a reduction of length one to the set of games where a goes over all values in {f (q) : f ∈ F A }, with ϕ and Φ both being identity maps.Moreover, for any two query games A, B such that B has a solution (q(t)) T t=1 , we have formed by the reduction 0 + q(t) for t = 1, . . ., T , ϕ(q) := q + 0 and Φ a (f where f a is the unique codeword in B consistent with the answer sequence a. We will refer to the query game whose only query is the zero-query and whose only codeword is the map 0 → 0 as the trivial game and denote it by ∅.Proof.(i) Reduction to the trivial game means that, for any f ′ ∈ F A consistent with a certain answer sequence a = (f (q(1), . . ., f (q(T ))), we have Hence the hidden codeword is given by Φ a (0 → 0).Conversely, any solution can be seen as a reduction to ∅ by putting ϕ ≡ 0 and Φ a ≡ f a where f a denotes the unique solution consistent with answers a.
(ii) Given any A = (Q A , F A ) ∈ A, we start by playing the strategy (q(t)) T t=1 from A T − → B and based on the answer sequence a compute the corresponding game B = (Q B , F B ), and the maps ϕ : Q B → Q A and Φ : F B → F A .We proceed by making the queries as dictated by the strategy (q ′ (s)) S s=1 from the reduction B S − → C, according to ϕ(q ′ (1)), ϕ(q ′ (2)), . . ., ϕ(q ′ (S)) and based on the answer sequence b compute the corresponding game C = (Q C , F C ), and the maps ϕ Note that for any choice f ∈ F A of the hidden codeword, asking any query ϕ(q) for q ∈ Q B is consistent with asking the query q in B with hidden codeword g := f • ϕ ∈ F B , hence b, C, ϕ ′ and Φ ′ will all be given as if strategy q ′ (s) was played on B with hidden codeword g.
We now argue that this is a well-defined reduction from A to C, as given by the game C and the maps ϕ • ϕ ′ and Φ • Φ ′ as given above.Indeed, for any function f ∈ F A consistent with the full answer sequence (a, b), that is, f (q(t)) = a(t) for all 1 ≤ t ≤ T and f (ϕ(q ′ (s))) = b(s) for all 1 ≤ s ≤ S, we have by the first reduction g By assumption on f , we have that g is consistent with answers b and hence g With these definitions at hand, we are now ready to present the main technical results of the paper.Given a sequence (A n ) n≥1 of sets of query games, it is natural to ask for a simple condition for the games to allow for short solutions.Our results give conditions for this to hold in terms of finding certain reductions.As we shall see in Section 3, such reductions appear naturally in many games.
For the first result, we say that a query game A has a simple reduction to B of length Theorem 2.5.Let (A n ) n≥1 be a sequence of sets of query games over the integers.If there exists a constant α > 0 such that

and, for all n
We will prove this in Section 4. This approach to find solutions to query games can be seen as a variation of the classical divide and conquer method, where Theorem 2.5 plays the role of the so-called Master theorem.However, constructing solutions from sequences of reductions as above will require combining reductions in a non-trivial way to form information-dense queries, which does not have an analogue in the usual divide-and-conquer setting.In particular, if one were to do all reductions indicated above to solve A n in sequence, this would result in a solution of length Θ(α • n log n).Instead, the solutions generated by Theorem 2.5 will compress the Θ(α • n log n) simple queries into Θ(α • n) actual queries with the same information content.
Simple reductions appear naturally in some query games, such as coin-weighing and the restriction of Mastermind to permutation codewords.However, in other games, such as Mastermind with general codewords, the requirement that queries must return 0 or 1 appears too restrictive.Finding a suitable set of queries may not be significantly easier than finding a solution, or perhaps even such queries do not exist at all.Our second result states that the requirement for the underlying reductions to be simple can be relaxed to allow any queries, but where queries that may return a large value are associated with a higher cost, or weight.
We say that a reduction (q(t)) t≥1 from A to B is bounded if there exists a function b(t) = b(t, f (q(1)), . . .f (q(t − 1))) such that 0 ≤ f (q(t)) ≤ b(t) for all t.We say that this reduction has weight at most T , A T B, if we have for any choice f of the hidden codeword.We have the following result.
Theorem 2.6.Let (A n ) n≥1 be a sequence of sets of query games over the integers.If there exists a constant α > 0 such that and, for all n ≥ 2 This will be shown in Section 5. We remark that, with a more careful analysis, log 2 (•) 2 could be replaced by a function of smaller growth.However, as this will not make a difference for our applications, we will not elaborate on this.Furthermore, as any simple reduction is by definition also bounded, Theorem 2.5 can be seen as a corollary of Theorem 2.6.We will still prove the two theorems independently.The proof of Theorem 2.5 is simpler, and can thus form as a warm-up for the general case.Moreover, the solutions constructed from simple reductions are arguably much simpler, and definitely shorter.

Applications
In this section, we will show how Theorems 2.5 and 2.6 can be used to prove the existence of efficient solutions to various classes of query games.We believe that these theorems apply in much greater generality, and we hope that this section can serve as inspiration to find solutions to other query games.In addition to being a powerful tool, our framework also has the benefit that a deep understanding of the underlying coin-weighing schemes is not needed to build solutions.
For any query game (Q, F), we define the information-theoretic lower bound as the expression A simple counting argument shows that any solution to (Q, F) needs at least this many queries.We will below give multiple examples of query games where our main technical results show that the information-theoretic lower bound is sharp up to constant factors.

Coin-weighing variations
Recall that C n , coin-weighing with n coins, is the query game where f (q) = |f ∩ q| for all f, q ∈ 2 [n] .The information-theoretic lower bound of this query game is given by n/ log 2 (n + 1).Multiple solutions that solve this problem within a constant factor of this lower bound have been given in [8,2,14].Let us reprove this statement using Theorem 2.5.
Proof.As Theorem 2. Let us make this more precise.We define k n recursively by k 1 = 1 and, for all n ≥ 2, Thus by the aforementioned strategy,

and clearly
Hence, by Theorem 2.5, coin-weighing with k n = Θ(n log n) coins can be solved in O(n) queries.
The proof above directly extends to any n-fold sum of query games where each game has a simple or a bounded solution.
Proposition 3.2.Let A be any set of query games such that A α ∅.Then the n-fold where k n is as in the proof of Proposition 3.1.We have that B 1 = A α ∅, and It follows by Theorem 2.6 that B n has a solution of length O(α • n).
In fact, we can extend this speed up also to sequences of query games satisfying similar conditions to Theorem 2.6, but where the splitting operation can be performed with sublinear weight.This is analogous to the leaf-heavy regime of the Master theorem for divide-and-conquer recurrences.Proposition 3.3.Let c > 0 be fixed.Let A n be a sequence of sets of query games such that for all n ≥ 2 and A 1 α ∅, for some α > 0. Then Proof.We begin by performing the following reductions in sequence where k ≥ 0 is an appropriately chosen integer.The total weight of the con- In particular, as the weight of a query is at least one, the total reduction has length ).We now solve the remaining sum of games in parallel.Let T k denote the minimum weight such that A k T k ∅.We have, by assumption, that T 1 ≤ α and Given the above propositions, we now turn to generalized versions of coin-weighing.First, Djačkov [6] and Lindström [15] proposed a sparse version of coin-weighing where the total number of counterfeit coins d is fixed beforehand.Formally, we can describe this as the query game for any 1 ≤ d ≤ n, and where, again, f (q) := |f ∩ q| for all q ∈ 2 [n] and f ∈ [n]  d .For d ≤ n/2, it can be seen that the information-theoretic lower bound is given by log 2 n d / log 2 (d+1), and, by symmetry, for d ≥ n/2 the bound is given by log 2 n d / log 2 (n− d + 1).We remark in the latter case that even though queries can return any value between 0 and d, no one fixed query can span this full range when d > n/2.
A second generalization of sparse coin-weighing is to allow the coins to have arbitrary non-negative integer weights where the total weight of the coins is known from the start of the game.Let us denote by C W n this version of coin-weighing with n coins where the total weight of coins is W . Here, the information-theoretic lower bound is given by log Coin-weighing with exactly one fake coin is of course a very classical problem, and is canonically solved by binary search.The reader is referred to [1] for an overview of research in the case of d = 2.In the general case, it was shown in 2000 by Grebinski and Kucherov [10] that the information-theoretic lower bounds for C n,d and C W n are tight up to constant factors in the full parameter range.As their solution is based on the probabilistic method, it is inherently non-constructive, and it took until 2009 before the first deterministic polynomial time solutions of the same lengths were found by Bshouty [1].
We will now use Proposition 3. ).This is a special case of (ii) for W = d.Hence, the proposition follows if we can prove (ii).To do this, let λ ≥ 2 and define We wish to apply Proposition 3.3 to the sequence A λ m m≥1 .We first claim that A λ 1 O(log λ) ∅.This is because the only non-trivial games in this set is C 1 n for 2 ≤ n ≤ λ, which can be solved in ⌈log 2 n⌉ simple queries using binary search.Second, let m ≥ 2 and let C W n be any query game in A λ m .Note that W ≤ 2m and n ≤ 2λm.To build our reduction, first determine the largest integer 0 As the left-hand side is increasing in i, this can be found in O(log n) queries using binary search.Given this i, we define L := {1, 2, . . ., i} and R := {i + 2, . . .n} and note that the subgames formed by the coins in L and R are in A λ ⌈m/2⌉ and A λ ⌊m/2⌋ respectively.Hence, by possibly performing one last query to determine the value of coin i + 1, we have the desired reduction.As the answer to any query used here is at most W ≤ 2m, we can bound the weight of this reduction by O(log(λm)(log m)

Mastermind with permutation codeword
We now turn our attention to Mastermind.In this subsection, as a warm-up, we consider the simplified version of black-peg Mastermind where the number of positions and colors are both n, and where the codeword chosen by Codemaker is required to be a permutation of [n].
We will formalize this in the query game setting as where S n denotes the set of permutations of [n], and where we interpret each f ∈ S n as a function from the queries to the natural numbers according to We remark that the query game formulation differs slightly from the game mentioned above in that Codebreaker may guess blank at certain positions of queries by putting q i = 0.This problem was previously considered by the author and Su in [16] where it was shown that it has a solution of length O(n).Indeed, as the information-theoretic lower bound is log n!/ log(n + 1) = Ω(n), this is optimal up to constants.In the same paper, it was shown that black-peg Mastermind with n = k has a randomized reduction to this game (Lemma 3.4, [16]).
We first prove that allowing blank guesses does not make the problem significantly easier, as blank guesses can be simulated in the usual game by performing a few additional queries.Proof.Observe that if we can identify a query b ∈ [n] n that has no matching entries with the hidden codeword, we can simulate guessing blank by replacing each instance of q i = 0 by the value b i .So it suffices to show that such a b can be found in 2⌈log 2 n⌉ queries.
For each i = 1, . . ., ⌈log 2 n⌉, we make two queries.In the first query, we guess 1 at all indices where the i:th least significant bit in its binary representation is a 0 and color 2 where the bit is a 1.In the second, we reverse the colors.
We claim that one of these queries must return 0. As the hidden codeword f is a permutation, there are unique indices j 1 , j 2 such that f j 1 = 1 and f j 2 = 2. Considering the binary representations of j 1 and j 2 , as they different numbers between 1 and n, there must be some position i in which the numbers have different digits.One of the two corresponding queries will return 0.
Proof.We prove this using Theorem 2.5.Note that M perm 1 is trivial -the only hidden codeword is "1", so we only need to consider the reduction of M perm n for n ≥ 2. Consider the strategy of length n formed by, for each 1 ≤ t ≤ n taking the query q(t) = (t, . . ., t, 0, . . ., 0) which is t in the first ⌈n/2⌉ entries, and 0 everywhere else, that is, it is 0 in the last ⌊n/2⌋ entries.Depending on whether color t is in the left or right half of the codeword, the t:th query will either return 1 or 0, so this strategy is simple.Moreover, given this information, we can treat the remaining game as a sum of two instances of Mastermind whose codewords are each a permutation of the colors t that returned 1 and 0 respectively, hence yielding a reduction to M perm ⌈n/2⌉ + M perm ⌊n/2⌋ .

Black-peg Mastermind
We now turn to the proof of Theorem 1.1.Consider full black-peg Mastermind game with n positions and k colors, with no restrictions on the codeword.The formalized version of this game was first considered by Chvátal [5].We will here formalize blackpeg Mastermind as the query game where, same as the previous section, we define f (q) := |{i : f i = q i }|.We will write M n to denote M n,n .We again start by showing that the assumption that Codebreaker can make blank guesses does not make the problem significantly easier by showing that blank guesses can be simulated in the usual version of the game.This uses a slightly more elaborate argument than in the last section.Proof.Analogous to Claim 3.5, it suffices to find a string b ∈ [k] n that does not match the codeword in any position.We will find such a b by determining, for each i ∈ [n], whether f i = 1, f i = 2, or f i ∈ {3, . . ., k}.
We first query the all ones string.Let us denote this by 1.After this, for any query q ∈ {1, 2} n we note that where we note that the summand in the right-hand side is always 0 for q i = 1, and for Hence this problem can be seen as equivalent to coin-weighing with weights 0, 1 and 2. This can be solved in O(n/ log n) queries using Proposition 3.2.
With this statement at hand, it remains to determine the optimal number of queries needed to solve M n,k .We have two natural lower bounds for this number.First, the information-theoretic lower bound is n log k/ log(n + 1).Second, for any index i ∈ [n] it may be that the value of f i is one of the two last colors to ever get queried in position i, meaning that no strategy is guaranteed to determine the codeword in fewer than k − 1 queries.Putting these together gives us a lower bound of We note that the first term dominates when k = o(n), the second term dominates when k = ω(n), and the terms are comparable when k = Θ(n).
In order to show that ( 3) is tight, we distinguish two parameter regimes.If k ≤ n 1−ε for any small fixed ε > 0, then it suffices to apply the sparse coin-weighing solution in Proposition 3.4 once for each color.Proposition 3.8 shows that this matches the information theoretic lower bound up to constant factors.
This is done in Observation 1 and Proposition 3.9, which finishes the proof of Theorem 1.1.It remains to show that the number of queries, has the prescribed upper bound.For this we consider three cases.First, there could be one color c for which d c > n/2.This will in worst case take as long as the dense coin-weighing problem, that is O(n/ log n).Second, the contribution from colors c such that n/k where the multinomial coefficient can be bounded by k n .Finally, the contribution from colors c where which is negligibly small.
It remains to show that M n,k has as solution of length O(n) + k for any k ≥ n 1−ε .In fact, this is true for any k ≥ 2. We show this in two steps.In the first step, we make queries (c, c, . . ., c) for all c ∈ [k] to determine the total number of times each color appears in the codeword.In the language of query games, this is a reduction from M n,k to the set of query games where M n (c 1 , c 2 , . . ., c k ) denotes the query game formed by restricting M n,k to only those codewords which has c 1 occurrences of color 1, c 2 of color 2 and so on.We can think of each query game M ∈ M n as an instance of Mastermind where Codebreaker is given hints consisting of how many times each color appears in the codeword.
In the second step, we apply Theorem 2.6 to solve M n in O(n) in a similar way to M perm n .The fact that we apply the framework to M n instead of M n,k means that the reductions need to be set up such that the resulting subgames still contain information about how many times each color appears.In fact, this is necessary to ensure that the reductions of the subgames are still bounded with an appropriate bound on its weight.
Proof.Using k queries, we determine for each i ∈ [k] the total number of times c i each color appears in the codeword.This forms a reduction with reduced game to Proof.We will show this using Theorem 2.6.M 1 is trivially solved as the hints of any game in this set uniquely determine the codeword.So it suffices to find a bounded reduction of M n for n ≥ 2.
Fix any M n (c 1 , c 2 , . . . ) ∈ M n .To form the reduction M n (c 1 , c 2 , . . . ) M ⌈n/2⌉ + M ⌊n/2⌋ , we make the following queries.For each i ≥ 1 such that c i > 0, query (i, . . ., i, 0, . . ., 0), where, similar to the previous subsection, the blocks denote the first ⌈n/2⌉ and the last ⌊n/2⌋ positions respectively.As we already know the total number of occurrences c i of color i in the codeword, we can use c i as an upper bound for this query.
Given this information, we can determine the number of times c ′ i each color i appears in the left half of the codeword, and how many times c ′′ i = c i − c ′ i it appears in the right half, which directly defines the reduced game , which shows that this is a reduction.Moreover, as

White-peg Mastermind and sparse set query
We now turn to determining the minimum number of queries needed to solve whitepeg Mastermind.Recall that this means that both black-and white-peg information is provided for each query.
Let us first discuss a bit how adding white-peg information changes the setting compared to black-peg Mastermind.The information-theoretic lower bounds for both of these games were discussed in the introduction, where we noted that the lower bound for white-peg Mastermind is a factor 2 + o(1) smaller than that that of black-peg Mastermind.As we already know that this bound is sharp up to constant factors when k = O(n).Thus for any k = O(n), white-peg Mastermind can be solved optimally up to constants by simply ignoring the white-peg answers, and apply the black-peg solution derived the in the previous section.
For k = o(n), the picture is even clearer.Observe that any solution to white-peg Mastermind can be turned into a solution to black-peg Mastermind by first making k queries to determine the number of times each color appears in the hidden codeword.As the number of queries needed to solve black-peg Mastermind is ω(k) when k = o(n) it follows that the length of optimal solutions to black-and white-peg Mastermind only differ by a factor 1 + o(1) in this range.
Instead, the regime where white pegs shine is when k = ω(n).Unlike for black-peg Mastermind where Codebreaker may need to try all but one color in each position of the query to get any positive indication for what colors are present in the codeword, in white-peg Mastermind Codebreaker can gain information about about occurrences of a certain color in the codeword by making queries that contain said color in any position.This lowers the combinatorial lower bound from Ω(k) to Ω(k/n).
Given the results for black-peg Mastermind, it only remains to consider the case where k = Ω(n), say k ≥ 2n, in which case we need a solution that matches the lower bound Ω(n + k/n).
To build our solution, we will determine which colors are actually present in the hidden codeword by observing the total number of (black and white) pegs returned from each query.Since the total number of colors present is clearly at most n, we already know how to solve the game optimally from that point.In order to approach this, we will consider a slightly cleaner version of the problem which we call sparse set query, as described in the introduction.For any k ≥ n, we define this as a query game where f (q) := |f ∩ q|.We can think of this as a variation of sparse coin-weighing with k coins, where we know that at most n coins are counterfeit, and where the scale fit at most n coins.Analogous to Mastermind, there are two natural lower bounds to the number of queries needed to solve this.On the one hand, the information-theoretic bound is log and Ω(k/ log(n + 1)) if n ≤ k < 2n.On the other hand, we need at least ⌈k/n⌉ queries to weigh each coin at least once.It is not too hard to see that the game can be solved in O(n/ log(n + 1)) queries when n ≤ k < 2n.For instance, one may divide [k] into two sets each with at most n elements and apply any efficient solution to the classical coin-weighing problem.So in order to solve this game optimally, it suffices to consider the case when k ≥ 2n.We will divide this further into two subcases.First, if k is polynomially smaller than n 2 , say 2n ≤ k ≤ n 2−ε for some ε > 0, then a direct application of sparse coin-weighing schemes shows that the information theoretic lower bound is sharp.This will be done in Proposition 3.10.Second, if k ≥ n 2−ε we can simplify the general lower bound to Ω ε (n + k/n).As we can always pretend to add additional dummy elements to the sets, we may in this latter case always assume that n ≥ k 2 , without affecting the lower bound.We will show in Proposition 3.11 that O(n + k/n) queries suffice in this case.This will conclude the proof of Theorem 1.3.
Proof.We build our solution as follows.Partition [k] into ⌈k/n⌉ sets D 1 , D 2 , . . . of size at most n.For each part D i we first query the full set to determine the number d i of counterfeit coins, and then use the sparse coin-weighing scheme from Proposition 3.4 to determine which coins are counterfeit.The number of queries needed for this is In order to bound this expression, let us distinguish terms in this sum depending on the size of d i .If d i < n ε/2 , we can bound the summand by O(d i log n) = O(n ε/2 log n), and thus the total contribution from such terms is at most O((k/n) • n ε/2 log n) ≤ O(n 1−ε/2 log n), which is polynomially smaller than n.In the case when d i ≥ n ε/2 , we have log(d i + 1) = Θ ε (log n), and thus the contribution from these terms are at most Proof.The first reduction can be done by querying the elements in groups of n and discarding elements in sets that return 0 until only n 2 elements remain.
For the solution to X n 2 ,n , we will apply Theorem 2.6.We start similarly to blackpeg Mastermind by making a sequence of queries to obtain upper bounds of parts of the codeword.In this case, fix a balanced n-partitioning and query these sets.This forms a reduction X n 2 ,n n − → X n 2 ,n to the set of games where the number of elements in common between each set D i and the codeword is fixed.Note that by definition X 1 2 ,1 is trivial, so again it suffices to find a bounded splitting reduction for n ≥ 2.
Fixing a game X(D 1 , d 1 , D 2 , d 2 , . . . ) ∈ X n 2 ,n in which the codeword is restricted to satisfying f (D i ) = d i for all i ∈ [n], we form this reduction as follows.For each i ∈ [n] such that d i > 0, we partition D i into three parts 3 each of size at most ⌊n/2⌋, and query the first two parts to determine f (D i,1 ), f (D i,2 ), and ).Given these function values, we greedily build two lists L and R consisting of sets with non-zero overlap with the codeword, under the condition that the total overlap between f and L is at most ⌈n/2⌉ and the total overlap between f and R is at most ⌊n/2⌋, and a set Z consisting of the union of all sets with no overlap with f .Note that as any set added to L and R contains at least one element, this implies that |L| ≤ ⌈n/2⌉ and |R| ≤ ⌊n/2⌋.This procedure will leave at most one set D i,j with non-trivial overlap with f that does not fit in either L nor R -if two such sets D, D ′ existed, then the total overlap of L ∪ D and f is greater than ⌈n/2⌉ and the total overlap between R ∪ D ′ and f is greater than ⌊n/2⌋, which is a contradiction as the total overlap is at most n.In case such a set D i,j occurs, we resolve it by querying its elements one at the time and distribute the singletons between L, R and Z.
Finally, we use the elements of Z to extend the lists L and R until they contain ⌈n/2⌉ sets of size ⌈n/2⌉ and ⌊n/2⌋ sets of size ⌊n/2⌋ respectively.This gives us a reduction to a sum of sparse set query on ∪ i L i and ∪ i R i respectively, with L and R describing the hints for the sub-games.
Finally, we need to check that this reduction has weight at most O(n).Indeed, using d i as upper bound when querying f (D i,1 ) and f (D i,2 ) gives a total weight of 2 i : For querying singletons of the remaining set, we make n queries with upper bound 1, whose weight is clearly also O(n), as desired.
With an efficient solution to the sparse set game at hand, we now come back to Theorem 1.2.
Proof of Theorem 1.2.As remarked, given Theorem 1.1, it remains to solve white-peg Mastermind in for k ≥ 2n in O(n + k/n) queries.We will do so by simulating sparse set query to find the set of colors present in the hidden codeword.Given this, we can apply the black-peg Mastermind algorithm to solve the rest in O(n) time.
We begin by identifying a color, call it z, that never appears in the hidden codeword.As k > n we know that one such color exists.Indeed, by asking all 'i' queries for i = 1, 2, . . ., n + 1, at least one of these must return 0 black and white pegs.
Given such a z, we next aim to determine the set a query such that each color of Y appears once in q Y , and all remaining positions are filled up with the color z.The total number of black and white pegs returned for any query q Y equals |X ∩ Y |, and thus by the preceding propositions, we can determine X in O(n log(k/n)/ log n + k/n) queries by simulating sparse set query.
With knowledge of the colors that appear in f , we can now apply the black-peg solution from Theorem 1.1 to determine the codeword after an additional O(n) queries, as desired.
4 Proof of Theorem 2.5 We now turn to the problem of constructing short solutions for query games satisfying the conditions of Theorem 2.5.As we shall see, after carefully setting up building blocks of the proof, the theorem can be shown by induction on n.This is inspired by the recursive construction by Cantor and Mills [2] for coin-weighing.
Before outlining our solution, let us take a moment to reflect on what to aim for.The only operations allowed to us by the theorem is the splitting and solving any term A 1 in α simple queries.By applying these operations sequentially, we would form a solution to A n in O(α • n log n) simple queries, which is too slow.To speed this up, the aim is that once the game is split into sufficiently many terms we can run the reductions more efficient in parallel.Indeed, as the answer to each individual query is known to be either 0 or 1 this parallelism is very similar to classical coinweighing.A natural approach to improve this is to consider a sequence of reductions layer by layer where reduction i = 1, . . ., O(log n), can be performed in Θ(α • n/2 i • 2 i /i) = Θ(α • n/i) queries by using standard coin-weighing schemes.But as this is still too slow.The reason why this is still not fast is that the coinweighing paradigm gives a meaningful speedup at first when the game is already split into many terms.In fact, it only gives the necessary factor log n speedup once the game has been split into n Ω(1) terms.While the layer-by-layer approach eventually attains this, it spends too much time initially to split all large (and therefore most costly to split) games at a time when no meaningful parallelism is possible.The way we remedy this is to consider an intermediate game P n , the preprocessed game, which is formed from A n by recursively applying the splitting operation a fraction of terms as they appear in the game.This has the strength that, on the one hand, one can reduce A n to P n using O(α • n) simple queries.On the other hand, P n consists of a sum of polynomially many A-games, meaning we can more directly apply coin-weighing techniques.
Before formally introducing the preprocessed game, we start by stating the lemma that will allow us to run reductions in parallel.Analogous to how we can determine the value of four coins in three weighings, this lemma states that, in the setting of sums of query games we can run four reductions in parallel at the cost (i.e.number of queries) of three of them, provided one reduction is simple.We will be able to construct efficient solutions by applying this recursively.We will choose the exact definition of the preprocessed game below so that it matches this statement nicely.Proof.Given games A, B, C, and D from the respective sets, and strategies (q A (t)) T t=1 , (q B (t)) T t=1 , (q C (t)) T t=1 and (q D (t)) T t=1 as in the statement of the lemma, we define a strategy (q(t)) 3T t=1 on A + B + C + D by, for each t = 1, . . ., T , letting q(3t − 2) := 0 + q B (t) + q C (t) + q D (t) q(3t − 1) := q A (t) + 0 + q C (t) + q D (t) q(3t) := q A (t) + q B (t) + 0 + q D (t), where for each t and each X ∈ {A, B, C, D}, the subquery q X (t) is generated as if past queries have returned f X (q X (1)), . . ., f X (q X (t − 1)) where f = f A + f B + f C + f D denotes the hidden codeword of the sum game.
To see that this is a well-defined strategy, we need to show that f X (q X (t)) can be uniquely determined by f (q(1)), . . ., f (q(3t)).Note that, given the answers to the first 3t queries, we can compute and as q D is simple, we can determine f D (q D (t)) by considering the parity of this sum.Given this, we can compute from which f A (q A (t)), f B (q B (t)) and f C (q C (t)) can be determined by linear algebra.
Secondly, to show that (q(t)) 3T t=1 is indeed the desired reduction, note that as (q A (t)) T t=1 , (q B (t)) T t=1 , and (q C (t)) T t=1 are solutions for their respective terms, the answers provided uniquely determine f A , f B and f C of the codeword.At the same time, for the subgame D = (Q D , F D ), the answers to (q D (t)) T t=1 determine a game E = (Q E , F E ) ∈ E and maps ϕ : Q E → Q D and Φ : F E → F D .One immediately checks that the maps q → 0 + 0 + 0 + ϕ(q) for q ∈ Q E and  ∅ for all n ≥ 0. We claim that this implies that Indeed, this can be shown by induction.For n = 0 the statement is clearly true with room to spare, and for the induction step one may apply Lemma 4.1 for Note that this solution resolves a total of (n + 1)3 n queries from the subgames by making 3 n+1 queries in the sum game.
With this lemma at hand, we are now ready to build our solution.For a given sequence of sets of query games A n as in Theorem 2.5, we define the preprocessed game P n , as follows We note that the indices of the four terms in the right-hand side is always equal to ⌈n/4⌉ or ⌊n/4⌋.In particular, ⌈⌈n/2⌉/2⌉ is always equal to the former, and ⌊⌊n/2⌋/2⌋ equal to the latter, and the sum of all four indices is n.
We now give a simple reduction from A n to the preprocessed game.This will be used both as the first step of the solution of A n , and also as a building block for the second step when solving P n .Claim 4.3.For any n ≥ 1, A n 8αn−7α P n .
Proof by induction.It is straightforward to check that the statement holds for n ≤ 3. We have Here, the reductions A 1 + A 1 ∅ and A 2 + A 1 ∅ are formed by solving the subgames one at a time through queries of the form q + 0 and 0 + q ′ .
For n ≥ 4, we have the following sequence of reductions With this at hand, we are now ready to construct the solution to the preprocessed game.where the last step is, again, by the induction hypothesis.Hence, it suffices to check that the length of the concatenated strategy 3T +8α(⌊n/4⌋− 1) is always at most 8α(n − 1).Indeed To conclude the proof of Theorem 2.5 we note by Claims 4.

Proof of Theorem 2.6
In this section, we modify the arguments from the last section to allow for queries whose answer can be larger than one, provided sensible upper bounds on each query are known beforehand.We will construct the solution in a very similar way to the previous section.We again use the preprocessed game (4) and define our solution around it recursively as before.The main challenge is how to generalize Lemma 4.1.
We will do this by showing that it is possible to replace the simple reduction in Lemma 4.1 with a reduction (q(t)) T t=1 with the property that f (q(t)) ∈ [0, r(t)] for all 1 ≤ t ≤ T and for a carefully chosen (non-adaptive) function r : {1, 2, . . .} → {0, 1, 2, . . .}.This comes with a few caveats.First, we can no longer allow arbitrary solutions for the first three terms, A, B, C, but the solutions need to have additional structure.Second, the choice of the function r(t) will depend on the solutions to A, B and C, so, rather, we will need to consider a set R and require that r-bounded reductions exist for all functions r(t) in R.
• for any pair of integers i ≥ 1 and 0 ≤ j ≤ 2 i − 1, there exists a constant a ij such that (x(t), y(t)) = (2 i , j) ⇔ t ≡ a ij mod 4 i .
It is not too hard to see that such pairs of functions exist.For instance, one can imagine going through the pairs (i, j) as above in lexicographical order and letting a ij be the smallest integer a ≥ 1 such that a ≡ a i ′ j ′ mod 4 i ′ for any (i ′ , j ′ ) < (i, j).Such an a always exists as the total density of integers covered by congruence classes (i ′ , j ′ ) < (i, j) For any pair (x(t), y(t)) t≥1 ∈ Q say that a reduction is (x(t), y(t))-bounded if it is r(t)-bounded for the function r(t) := ½ y(t)=0 (2 x(t) − 1).We say that a reduction is (x(t), y(t))-predictable if it is p(t)-predictable for p(t) := 2 y(t) .We will write Proof.Let A, B, C, D be query games from the respective sets, and let (x(t), y(t)) ∈ Q.We construct a (x(t), y(t))-predictable reduction from A + B + C + D to E as follows.
We first show that this is a well-defined reduction to E. Let f = f A + f B + f C + f d denote the hidden codeword.Similar to Lemma 4.1, it suffices to prove that f (q(1)), . . ., f (q(3t)) uniquely determines the subqueries f A (q A (t)), f B (q B (t−1)), f C (q C (t− 2)) and f D (q D (t)) for each 1 ≤ t ≤ T + 2. We will show this by induction on t.For any given 1 ≤ t ≤ T + 2, we may assume that we have already determined f A (q A (s)) for all s < t, f B (q B (s)) for all s < t − 1, and f C (q C (s)) for all s < t − 2. Observe that it is sufficient to determine f D (q D (t)), as the answers to the remaining subqueries then can be extracted by linear algebra.In particular, this trivially holds for any t such that y(t) > 0 as then f D (q D (t)) = 0.
We conclude that q(t) is a well-defined reduction to E.
Finally, we need to check that q(t) is (x(t), y(t))-predictable, that is, f (q(3t)) mod 2 y(t) is uniquely determined from f (q(1)), . . ., f (q(3t − 1)).Note that this is a trivial statement if y(t) = 0.For any t ≥ 1 such that y(t) > 0 we know that f D (q D (t)) = 0 and again by case distinction on t mod 3, one can see that f (q(1)), . . .f (q(3t − 1)) uniquely determine the congruence class of f A (q A (t)), f B (q B (t − 1)) or f C (q C (t − 2)) mod 2 y(t)−1 .The statement follows as before by linear algebra.Proof.Let (x(t), y(t)) ∈ Q be given.Observe that any linear shift ((x(t + a), y(t + a)) is also contained in Q.For (i) we concatenate a (x(t), y(t))-bounded reduction from A to B with a ((x(t + T ), y(t + T ))-bounded reduction from B to C. For (i) we concatenate a ((x(t), y(t))-predictable strategy from A to B with a (x(T /3 + t), y(T /3 + t))-predictable strategy from B to C.
We now turn to proving Theorem 5.The following statement is proven identically to Claim 4.3, using Proposition 5.4 to concatenate the strategies. .
By concatenating the reductions from the two claims above, we conclude that A n has a solution of length 8βn − 7β + 8β(n − 1) = 16βn − 15β, which concludes the proof of Theorem 5.2.

Conclusion
In conclusion, we have demonstrated the versatility of the framework presented in Section 2 for finding optimal solutions to a wide range of guessing games over integers.Hopefully, this paper can act as a guide to finding solutions to further games in the future.
While this paper has focused on proving the existence of solutions, with little discussion on how these may look, it is worth noting that any solution given by Theorems 2.5 and 2.6 can be efficiently implemented, provided that the elementary reductions have efficient implementations.More precisely, in order to show that a solution given by either of these theorems has a polynomial time implementation, it is sufficient to show that there is an efficient way to implement the reductions (q(t)) T t=1 , the pairs of query games A + B produced by the reductions, and the maps ϕ, Φ.In fact, the map Φ is only needed to ensure that decoding the codeword can be done efficiently.
Additionally, while we have not optimized constants in our solutions, it would be interesting to see how close the lower bounds one can push these constructions.For example, for black-peg Mastermind with n colors and positions, the argument in the paper shows that the minimum number of queries needed lies between n and 129n+o(n).It seems likely that the length of the optimal solution for this problem grows as c • n for some small constant c > 1. Resolving this completely may be difficult due to the longstanding remaining factor 2 gap for adaptive coin-weighing, but it would be interesting to see how much this gap could be narrowed.
with the answer sequence a.We denote by A T − → B that A T − → B for all A ∈ A. With slight abuse of notation, we will write A T − → B and A T − → B to denote reduction to the set {B}.

Proposition 2 . 4 .
Let T, S ≥ 1 and let A, B and C be sets of query games.The following holds: (i) A T − → ∅ if and only if each A ∈ A has a solution of length T , (ii) if A T − → B and B S − → C then the strategy formed by concatenating the respective reductions forms a reduction A T +S − −− → C.
Applying Proposition 3.2 to the remaining game, with n ′ = Θ( √ n) equal to the number of terms and α ′ = O c (α √ n) equal to the maximum weight needed to solve each individual term, it follows that A n can be solved in O c (αn 1−c/2 + αn/ log(n + 1)) = O c (αn/ log(n + 1)) queries, as desired.

Proposition 3 . 4 .
3 to derive optimal solutions to C n,d for all n, d and for C W n in the case where W = O(n).Let n, d, W ≥ 1 be such that d ≤ n.Then (i) C n,d can be solved in O(log n d / log(min(d + 1, n − d + 1))) queries, and (ii) C W n can be solved in O (max(1, log(n/W ))W/ log(W + 1)) queries.Proof.By symmetry between genuine and counterfeit coins, it suffices to show (i) for d ≤ n/2, in which case the upper bound simplifies to O(d log(n/d)/ log(d + 1) 2 ) = O(log λ) • polylog(m).Applying Proposition 3.3 to A λ m with α = O(log λ)) and, say, c = 1 2 , it follows that A λ m O(log λ•m/ log(m+1)) −−−−−−−−−−−−−→ ∅.For any given n, W ≥ 1, the result follows by noting that C W n ∈ A λ W where λ := max (2, n/W ).

Claim 3 . 5 .
If M perm n T− → ∅, then black-peg Mastermind with a permutation codeword (without blank guesses) can be solved in T + 2⌈log 2 n⌉ queries.

Claim 3 . 7 .
If M n,k T − → ∅, then black-peg Mastermind with n slots and k ≥ 2 colors can be solved in T + O(n/ log n) queries.

Proposition 3 . 8 .
For any ε > 0 and 2 ≤ k ≤ n 1−ε , the game M n,k can be solved in O ε (n log k/ log n) queries.Proof.For each color c = 1, 2, . . .k, we first ask the all 'c' query to determine how many times d c the color c appears in the hidden codeword.If d c ≥ 1, we apply the solution from Proposition 3.4 to determine the positions of the d c occurrences of the color by making queries in {0, c} n .Observe that, since we already know the colors at d 1 + d 2 + • • • + d c−1 positions, we may assume when applying Proposition 3.4 that the total number of coins is n − c ′ <c d c ′ .
the reduction is bounded with weight O(n).By Theorem 2.6, it follows that M n O(n) − −− → ∅, as desired.

Lemma 4 . 1 .
Let T > 0 and let A, B, C, D, E be sets of query games such that A Then A + B + C + D 3T −→ E.
the definition of a reduction from A + B + C + D to E, as desired.

Remark 4 . 2 .
To illustrate the strength of applying Lemma 4.1, consider any sets of games B n such that B n 3 n

Proposition 5 . 4 .C
Let Q be as above, let T, S ≥ 1 and let A, B and C be sets of query games.The following holds: and T is divisible by three, then AT +S = == ⇒ Q C.

Claim 5 . 5 .
For any n ≥ 1, A n 8βn−7β − −−−− → Q P n .Secondly, we can show that P n has an Q-predictable solution in 8β(n − 1) time in the same way as Claim 4.4 but replacing Lemma 4.1 by Lemma 5.3.Note that the latter lemma adds 6 additional queries to the length of the combined reduction, but the inequalities at the end of Claim 4.4 has room to spare for this.Claim 5.6.For any n ≥ 1, P n 8β(n−1) =====⇒ Q ∅.
Theorem 1.1.The minimum number of adaptive queries needed to solve black-peg Mastermind with n positions and k ≥ 2 colors is Θ n log k log n + k .
5 always gives solutions of length O(n), we aim to apply it to a sequence C Θ(n log 2 n) n≥1 .The key condition to verify is the existence of a simple re- duction of length O(n) from coin-weighing with Θ(n log 2 n) coins to Θ((n/2) log 2 (n/2)+ (n/2) log 2 (n/2)) coins.But as(n/2) log 2 (n/2) + (n/2) log 2 (n/2) = n log 2 n − n,this can be done by weighing Θ(n) coins one by one, and dividing the remaining ones into two piles of appropriate sizes.