## TUTORIAL ON MASTERMIND CODEBREAKING STRATEGY (1) (THE SIMPLEST GAME SETTING)

Game Setting: No. of colours: 7; Start from: Trial 1; Length of code: 4; Hints contain error(s)?: No error; Order type: Fixed order; Colour repeated?: No repetition

Code: 1345

In the beginning we can input any 4 digits. Suppose we input 0123 and the hint is 2 (i.e. we get 2 digits correct). In order to trace our reasoning procedure effectively, a Trace Table will be given below. The Trace Table will include such information as the Codebreaker's input, hint obtained, the new digits used in each round of guess and the digit(s) assumed to be correct among the new digits used in a particular round of guess. At the end of the 1st Round, we get the following Trace Table:

RoundInputHintNew Digits Used in this RoundDigit(s) Assumed to be Correct
1012320123-

Then we enter the 2nd Round. At first we review the guess result in the 1st Round. As we got 2 digits correct in the 1st Round, we may assume those 2 digits to be 01. In addition, we also need two new digits 45. After inputting 0145, the hint is 3. Thus at the end of the 2nd Round, the Trace Table becomes:

RoundInputHintNew Digits Used in this RoundDigit(s) Assumed to be Correct
101232012301
20145345-

Next we enter the 3rd Round and review our guess result in the 2nd Round first. As in the 2nd Round we got one more correct digit as compared with the 1st Round, we assume that this correct digit is 4. As we now assume that the correct digits are 014, we still need one new digit 6. After inputting 0146, the hint is 2. Thus at the end of the 3rd Round, the Trace Table becomes:

RoundInputHintNew Digits Used in this RoundDigit(s) Assumed to be Correct
101232012301
201453454
3014626-

Next we enter the 4th Round and review our guess result in the 3rd Round first. Since in the 3rd Round we previously assumed that 014 were the correct digits but the hint we got was 2, this shows that our previous assumptions are incorrect. So we must go back to modify our assumptions. We first go back to the 2nd Round and change the "Digit(s) Assumed to be Correct" to 5. This means that we now assume the correct digits to be 015. Having modified our assumption, we proceed forward again and consider the guess result of the 3rd Round. Comparing 015 with our guess in the 3rd Round - 0146, we get the following conclusion: if the Code really contains 015, then our guess 0146 in the 3rd Round should contain at least 2 correct digits. As a matter of fact, the hint for the 3rd Round is exactly 2. That means the new digit 6 used in the 3rd Round is not included in the Code. But if this were the case, there would be no more new digits for us to use (according to the Game Setting, the no. of colours for this game is 7, represented by 0,1...6, respectively). This shows that our previous assumptions are incorrect and so we must go back to modify our assumptions again.

We first return to the 2nd Round. As the digit(s) assumed to be correct in the 2nd Round is now 5, which is already the last possible correct digit and thus unchangeable. So we move on to the 1st Round. The digit(s) assumed to be corect in the 1st Round is 01, which is changeable, and so we change it to 02. Next we proceed forward again. First we come to the 2nd Round. Comparing 02 and our guess in that Round - 0145, we get the following conclusion: if the Code really contains 02, then our guess 0145 in the 2nd Round should contain at least 1 correct digit. As a matter of fact, the hint for the 2nd Round is 3, which is 2 more than what we expected. Thus these two digits must be 45. Next we proceed onward to the 3rd Round. Comparing 0245 with our guess in that Round - 0146, we get the following conclusion: if the Code is really 0245, then our guess 0146 in the 3rd Round should contain 2 correct digits. And in fact the hint for the 3rd Round is exactly 2, which does not contradict our assumptions. Moreover, as our assumed Code 0245 now contains 4 digits, no more new digits are needed, this is a reasonable guess. We next input 0245 and the hint is 2. Thus at the end of the 4th Round, the Trace Table becomes:

RoundInputHintNew Digits Used in this RoundDigit(s) Assumed to be Correct
101232012302
2014534545
3014626-
402452--

Next we enter the 5th Round and review our guess result in the 4th Round first. As we assumed the correct digits to be 0245 in the 4th Round but our hint was only 2, this means our previous assumptions are incorrect and so we need to go back to modify our previous assumptions. First we return to the 3rd Round. Since there is no digit assumed to be correct in the 3rd Round, we move on to the 2nd Round. As the digit(s) assumed to be correct in the 2nd Round is 45, which is unchangeable, we further move on to the 1st Round and change the digit(s) assumed to be correct in the 1st Round to 03. Having done this, we proceed forward again. We first come to the 2nd Round. Comparing 03 and our guess in that Round - 0145, we get the following conclusion: if the Code really contains 03, then our guess 0145 in the 2nd Round should contain at least 1 correct digit. As a matter of fact, the hint for the 2nd Round is 3, which is 2 more than what we expected. So these two digits must be 45. Next we proceed to the 3rd Round. Comparing 0345 with our guess in that Round - 0146, we get the following conclusion: if the Code is really 0345, then our guess 0146 in the 3rd Round should contain 2 correct digits. And in fact the hint for the 3rd Round is esactly 2, which is consistent with our assumptions. Next we proceed to the 4th Round. Comparing 0345 with our guess in that Round - 0245, we get the following conclusion: if the Code is really 0345, then we should get at least 3 correct digits in the 4th Round. But in fact the hint for the 4th Round is 2, which is 1 less than what we expected. This means that our previous assumptions are incorrect and so we must go back again to modify our previous assumptions.

As shown in the last paragraph, the digit(s) assumed to be correct in the 3rd and 2nd Rounds are unchangeable. Thus we must go back to the 1st Round and change the digit(s) assumed to be correct in the 1st Round to 12. Then we proceed forward to the 2nd Round again. Comparing 12 and 0145, we conclude that if the Code really contains 12, then we should get at least 1 correct digit in the 2nd Round. As the hint for the 2nd Round is 3, which is 2 more than what we expected, these two digits must be 45. Next we proceed onward to the 3rd Round. Comparing 1245 and 0146, we conclude that if the Code is really 1245, then we should get 2 correct digits in the 3rd Round. As the hint for the 3rd Round is exactly 2, this is consistent with our assumptions. Next we proceed onward to the 4th Round. Comparing 1245 and 0245, we conclude that if the Code is really 1245, then we should get 3 correct digits in the 4th Round. But the hint for the 4th Round is 2, which is contradictory with our assumptions. This shows that our previous assumptions are still incorrect and so we must go back once again to modify our previous assumptions.

We return to the 1st Round once again and change the digit(s) assumed to correct in that Round to 13. Next we proceed forward again to the 2nd Round. Comparing 13 and 0145, we conclude that if the Code really contains 13, then we should get at least 1 correct digit in the 2nd Round. As the hint for the 2nd Round is 3, which is 2 more than what we expected, these two digits must be 45. Next we proceed onward to the 3rd Round. Comparing 1345 with 0146, we conclude that if the Code is really 1345, then we should get 2 correct digits in the 3rd Round. As the hint for the 3rd Round is exactly 2, this is consistent with our assumptions. Next we proceed onward to the 4th Round. Comparing 1345 and 0245, we conclude that if the Code is really 1345, we should get 2 correct digits in the 4th Round. As the hint for the 4th Round is exactly 2, this is again consistent with our assumptions. Now our assumed Code 1345 is consistent with the hints for the 1st to the 4th Rounds and contains exactly 4 digits. Next we input 1345 and as result, we win the game. At the end of the 5th Round, our Trace Table becomes:

RoundInputHintNew Digits Used in this RoundDigit(s) Assumed to be Correct
101232012313
2014534545
3014626-
402452--
51345WIN--

To summarize, the strategy I introduce here for breaking Mastermind Codes is a repetitive process of making assumptions and modifying assumptions according to the hints. Our assumptions are made in stages. We conjecture which new digit(s) used in each Round may be included in the Code according to the guess result (i.e. hint) of that particular Round. Whenever we find that our assumptions are incorrect, we go back to modify our previous assumptions. As our strategy is to avoid any omission in our reasoning, we make the least possible modification each time, i.e. we try to move just one step back to the previous Round and modify the assumption made in that Round wherever possible. But if the assumption made in the previous Round is unchangeable, we cannot but move one more step back until we find a changeable assumption. After modifying our assumption, we must proceed onward again to check if our new assumptions contradict the guess result of the next Round. If so, this means that our new assumptions are still incorrect and we must go back again to make further modification to our assumptions. If not, then we continue to proceed forward until we prove that our new assumptions are consistent with all the guess results. By that time we can then input our new guess. In short, in the process of making guesses we repetitively move backward and forward to review the guess results currently available and do our best to make use of any hints already at hand as well as avoid omitting any possibilties. Go toMastermind Link Page.