Mastermind is a well-known game. Here's a brief reminder of the rules:

  • There's a secret code consisting of a sequence of five colored circles (items). Colors may appear more than once.
  • Your job is to figure out the code. You do so by guessing a sequence of five colors and then getting feedback on your guess.
  • The feedback consists of a number of black and white markers:
    • Black: you receive a black peg for each item of the correct color in the correct place.
    • White: of the remaining items, you receive a white peg for each one of a correct color but in the wrong place.
  • You receive at most one peg per item of the correct secret code.
  • The order of the black and white pegs has no significance
  • Example: suppose the secret code is RGGGG. If you guess RRRRR, you will receive 1 black (for the first R) and 0 whites. If you guess GBBBB, you will get 1 white and 0 blacks.

In this puzzle, you have had a few guesses already and are ready to guess again. Can you determine the secret code?

Mastermind Game

  • $\begingroup$ Can there be duplicate colors in the code? $\endgroup$
    – Gymhgy
    Aug 8, 2019 at 12:13
  • $\begingroup$ Yes. I'll add a point to clarify that. $\endgroup$
    – Dr Xorile
    Aug 8, 2019 at 12:14
  • $\begingroup$ If the solution is ABCDE and I guess AAAAA do I get one black and four white? $\endgroup$
    – LeppyR64
    Aug 8, 2019 at 12:17
  • $\begingroup$ No. You get one black. See my new edits. $\endgroup$
    – Dr Xorile
    Aug 8, 2019 at 12:18
  • 1
    $\begingroup$ Bayl gur ynfg gjb yvarf ner arrqrq evtug? (rot13) $\endgroup$ Aug 9, 2019 at 0:58

2 Answers 2


The secret code is:


Explanation: At first glance, my gut instinct (soon to be proved wrong) told me this must be impossible! After all:

If the two rightmost pegs have been swapped from guess#3 to guess#4 and we still have 3 black and 2 white markers, then they cannot both have been correct on guess#3 and still both be correct on guess#4 (contradiction).
Equally, they cannot both have been mis-positioned on guess#3 and still both be mis-positioned on guess#4 (since that would require 2 of the first 3 pegs to be mis-positioned also, but we only have 2 white markers, not 4).

However, then I realised I had completely overlooked the possibility that:

The two rightmost pegs are supposed to be identical, and so only one of the green and purple was correct and the other mis-positioned both times.

Which colour could this be? Well, we know from guess#3 and guess#4 that we have to have:

1 red, 1 yellow, 1 green and 2 purples in total (since all 5 markers are present, meaning we have all the right colours, just not all in the right positions yet...)


The two rightmost pegs must be PURPLE, since all other colours are only represented once.

It now follows that the other three must be ordered as:

RED - GREEN - YELLOW... since on guess#3 and guess#4 two of the black markers must have been referring to the first three pegs, and could not have been referring to the purple in slot 2 (which should have been in slot 4 or 5, and was therefore represented by a white marker). Therefore the red must be in slot 1, the yellow must be in slot 3 and - by deduction - the green goes in slot 2.

Meaning the final solution is as outlined at the top.

  • 1
    $\begingroup$ great minds think alike +1 $\endgroup$ Aug 8, 2019 at 12:18
  • 3
    $\begingroup$ Great job. This was an actual game on Simon Tatham's puzzles and I also had the “wait, that's impossible” moment. Thought I'd share. Of course, it took SE almost no time to get it... $\endgroup$
    – Dr Xorile
    Aug 8, 2019 at 14:10

The answer is

Red Green Yellow Purple Purple

I don't know what to explain...


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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