# Can somebody answer this 'Crack the code'?

Can somebody answer this? It was given to me as a challenge and I am having doubts in my answer

Text version:

2 6 5 7 - Has two correct digits but neither are in the correct place
0 4 1 5 - Has one correct digit but it's in the wrong place
4 2 6 8 - Has no correct digits
1 7 4 9 - Has two correct digits, both in the correct place

• Hi! Welcome to puzzling SE :) I would suggest to change the title to be more specific and move the current title to the question body. Also, keep in mind that you're not supposed to post homework question here if it is one. – newbie Apr 11 at 3:29
• And most definitely not riddle. No worries @newbie, I removed those tags. – Rand al'Thor Apr 11 at 3:35
• Beatriz, you say this was "given to you as a challenge" - can you please edit to include the source? – Rand al'Thor Apr 11 at 3:43

This is a tricky one, because one of the solution digits is never seen! It must be deduced by elimination.

• From the 3rd clue, we know $$2,4,6,8$$ are NOT in the solution.

• So, in the 1st clue, the correct digits must be $$5,7$$ (not $$2$$ or $$6$$), but both in the wrong place.

• So, in the 2nd clue, the correct digit must be $$5$$, again in the wrong place. That means $$0,1$$ are NOT in the solution.

• In the 4th clue, we know $$1$$ and $$4$$ are not in the solution, so it must be $$7$$ in the 2nd place and $$9$$ in the 4th place.

• We also know $$5$$ is in the solution, not in the 3rd or 4th place, so it must now be in the 1st place.

• We already used $$5,7,9$$, and we know $$0,1,2,4,6,8$$ are not in the solution, so the last digit must be $$3$$ (the only one remaining), in the 3rd place.

So the solution is

$$5739$$.

• Is there a rule that a digit can't be used more than once in the code? It seems to me that the third position could contain two other digits, if repeats are allowed. – Lanny Strack Apr 11 at 5:41
• @LannyStrack Assuming the solution has to be unique, yes ;-) – Rand al'Thor Apr 11 at 5:59
• Yet another reason why these types of clickbait puzzles are worthless. – Lanny Strack Apr 11 at 6:07

Using the old Mastermind game colors of B = correct in correct place and W = correct in wrong place, we have the following clues:

a. 2657 WW
b. 0415 W
c. 4268
d. 1749 BB

Solution:

1. From c, we know that

2, 4, 6, 8 are not in the code.

2. From 1 and a, we know that

5 and 7 are in the code, but not in the 3rd and 4th slots respectively.

3. From 2 and b, we know that

5 is in the code, but not in the 3rd or 4th slots. We also know that 0, 1 are not in the code.

4. From 1 and 3, we know that

1 and 4 are not in the code, so from d, we know that 7 and 9 are in the code and in the 2nd and 4th slots: x7x9

5. From 3 and 4, we know that

5 is in the 1st slot: 57x9

At this point, we know that the following are not in the code:

0, 1, 2, 4, 6, 8.

Now, the rules of Mastermind

allow duplicates, [see footnote]

so we cannot rule out the following:

5779
5799

Note that we cannot have

5759

because

we know from 1 that 5 is not in the 3rd slot.

Footnote:

An article in the October 1977 issue of Byte Magazine describes the tabletop Mastermind game, distributed by Invicta Plastics, that was hugely popular in the mid-1970s, and provides a BASIC implementation of the game. In giving the rules, the article states, "It is acceptable to use the same color or colors more than once." I think I have this version of the original game somewhere, probably with the original rule sheet. In the meantime, here is an image of that Byte article:

• The rules of Mastermind allow duplicates? Not the Mastermind I've always played. – Rand al'Thor Apr 11 at 6:46
• @Randal'Thor Edited with footnote – shoover Apr 11 at 7:10
• Yes, according to the official rules, you may use duplicate colors. I have a copy of the original game but not 100% sure it still has the instructions. Nevertheless, the wikipedia page on the game includes this rule in the description: en.wikipedia.org/wiki/… – 3d12 Apr 11 at 19:31
• Here's an image of the original game box cover: i.stack.imgur.com/N1XDS.jpg. It clearly states, "Use 2 or more Code Pegs of the same colour[sic] if you wish." @Randal'Thor, you had a deprived childhood. – Lanny Strack Apr 12 at 3:24
• @LannyStrack I have that box somewhere, with the game still inside. – shoover Apr 12 at 4:12

This answer is only true if you disregard the rules that the tag implies. Nothing except the tag hints that masterminds rules should apply here and usually when these things are passed around they do not come with Masterminds rules included. That tag was also not put there by the person asking the question, so I will look at only what is written on that piece of paper.

In my opinion this puzzle has technically 13 possible solutions and each one of those is equally valid.

The statements, lets call them a, b, c and d:

a - 2 6 5 7 - Has two correct digits but neither are in the correct place
b - 0 4 1 5 - Has one correct digit but it's in the wrong place
c - 4 2 6 8 - Has no correct digits
d - 1 7 4 9 - Has two correct digits, both in the correct place

Starting with c we know that 4 2 6 8 are not in the correct combination, so valid digits are 013579, lets call them X. There are 6 possible digits so we have 6*6*6*6=1296 possible combinations:
XXXX

By combining c and d we know that 4 can not be in the solution. And given that two numbers are in the correct position we can narrow the possibilities down by quite a bit. The only possible options now are:
XXXX
17XX, 1XX9, X7X9 (possible combinations of two numbers being in correct positions, excluding 4)
In total this is 6*6+6*6+6*6=108 possible solutions with these two rules.

Adding the statement a narrows it down further. 2 and 6 can not be in the solution (statement c), so 5 and 7 must be in the solution and as they are presented they are in the wrong place.
XXXX
17XX, 1XX9, X7X9
17X5, 1579, 57X9 (5 can not be in the third position)
This brings the number of possible solutions down to 6+1+6=13

This is also as low as I think it is possible to get with the given input, statement b is true regardless of the value of X. All of the 13 possible combinations of 17X5, 57X9 and 1579 where X is [0, 1, 3, 5, 7, 9] satisfy all of the statements.

I will take X=0 with both combinations that contain X for the examples(1705, 5709). Parts of the number that satisfies each statement is in bold.

a - 2 6 5 7 - Has two correct digits but neither are in the correct place
1705, 5709
b - 0 4 1 5 - Has one correct digit but it's in the wrong place
1705 , 5709 Having two improperly placed correct numbers and only stating one contradicts masterminds rules, but does not contradict the fact, that a correct digit is out of place.
c - 4 2 6 8 - Has no correct digits
1705, 5709
d - 1 7 4 9 - Has two correct digits, both in the correct place
1705, 5709

The only line where the variables X is highlighted is with statement b and that statement is satisfied regardless of what value the X has.