I have just started self-studying with Alan Tucker's Applied Combinatorics. The intro to the book is a series of problems based on the game Mastermind, which I have had a good amount of success with. However, I am stuck on the following problem.

In Mastermind, there is a "secret code" made up of four colored pegs. These pegs can be Blue, Red, Green, Yellow, Black, or White, and repetitions are allowed (so Blue Green Red Green and Blue Yellow Black White are both valid secret codes). A player takes turns guessing the code, and their guesses are scored with black and white keys. The guess gets one black key for each peg that is the right color and in the right location, and one white key for each peg that is the right color but in the wrong position. Each guess can only have four keys, and each peg can only have one key (a peg that gets a black key cannot also get a white key).

With those rules in mind, I have the following problem.

What are the two possible secret codes (one of them has no repeated colors)?

Guess 1: Black Blue Yellow White - 2 white keys

Guess 2: Red White Blue Green - 1 black key, 2 white keys

Guess 3: Blue Green Red Green - 2 white keys

Guess 4: Yellow Red White Blue - 1 black key, 2 white keys

My general strategy for solving these problems has been to make a grid and mark out what I know cannot be true (so the top of the table is the positions 1 2 3 4 and the side is all of the colors).

So far, all I have been able to deduce about this problem is that none of the position/color combos in guesses 1 or 3 is correct, and I do not know where to go from here.

Am I approaching this type of problem incorrectly or am I just missing something?

  • 1
    $\begingroup$ I would be nice if your question were a bit more self-contained. It might be helpful if you reminded us of the rules of Mastermind. For example, I don't recall which of black and white indicates a correct color in the correct place. Others may be entirely unfamiliar with the game. $\endgroup$ – Xander Henderson Jun 10 '18 at 22:00
  • $\begingroup$ @XanderHenderson I have added them, let me know if any part of them is unclear. $\endgroup$ – wz-billings Jun 10 '18 at 22:08
  • $\begingroup$ White,Red,Blue,Red seems to work ... but the logic is lengthy & gruesome $\ddot \frown$ $\endgroup$ – Donald Splutterwit Jun 11 '18 at 0:06

From line $1$ we get that if all the colours are different we must include R+G (use Bl for blue, B for black). Then line $3$ tells us that blue is impossible, so from line 2 we must have R+W+G and from line 4 we have R+W+Y so the colours are $R+W+G+Y$.

Line $3$ tells us that $G$ is in place 1 or 3 and can't be in the correct position in line 2.

Put G in place 1. Then if White is in the right place in line 2, there is no possibility for line 4. There are no other possibilities to fit line 2.

So try G in place 3. If R is in place 1 to meet the correct place in line 2 then W must be in position 4 o meet line 2, but thid is impossible according to line 1. If instead we have $W$ in the correct position in line 2 we must have R in place 4 and $Y,W,G,R$ which checks out.

Now if a colour is doubled it must appear in any collection which matches 3, and hence in both lines 2 and 4 so must be Red, White or Blue (and not Green)

Then there are only three colours altogether. If these include W from line 2 they must also include Y from line 4 (replacing an included colour with an excluded one changes the number of matches). But then matching two colours in line 3 gives four different colours (no double green), so the three colours must be $R,W,Bl$.

From lines 1 and 3 we can't have blue in places 1 or 2, so try Blue in position 3. Then we must have White in position 1 (line 2) and Red in position 2 (can't now have white - line 2), and then Red is the only possibility for position $4$ (lines 1 and 4 exclude the others). So $W, R, Bl, R$

Next try Blue in position 4 (and not in position 3) - then there is no possibility for position 3 - can't be blue by assumption and lines 3 and 4 exclude Red and White.

I hope this illustrates some of the ways in which the number of possibilities can be reduced.

  • $\begingroup$ Thank you! I understand most of this, but could you explain a little more about how R, W, and Bl can be the only three colors in the second guess? I know you can rule out G from guess 3, but does only have R, W, and Bl left in guess 2 exclude the possibility of any other color? $\endgroup$ – wz-billings Jun 12 '18 at 0:52
  • 1
    $\begingroup$ @jeanquilt Ignoring the difference between the black and white keys, think about the fact that you have three keys in lines 2 and 4. Each of these lines has four different colours, so the solution must have at least three different colours just by looking at line 2 (three of the four must be in the solution). Suppose these colours include Green, then they must miss one of Red, White and Blue. Then in line four, the three colours must include Yellow and you have the collection of four different colours which made the first solution. If you want just three colours there is only one option. $\endgroup$ – Mark Bennet Jun 12 '18 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.