Solution
Cracking the Four-Digit Lock
Show the problem again
A lock has a four-digit code in which no digit repeats (leading zeros are allowed). Five guesses were made, each with no repeated digit. For each guess you are told how many of its digits appear in the code in the same position ("right place") and how many appear in the code but in a different position ("wrong place"): - 6932: 0 in the right place, 1 in the wrong place - 8753: 0 in the right place, 3 in the wrong place - 3621: 0 in the right place, 1 in the wrong place - 8354: 1 in the right place, 1 in the wrong place - 7295: 2 in the right place, 0 in the wrong place What is the code?
Worked solution
Start with 7295, which has two digits in the right place and two digits that are not in the code at all. Suppose 2 were in the code (so, in place, in position 2). Then 6932 and 3621 each already hold their single allowed code digit, so 6, 9, 3, 1 are absent; but 8753 needs three code digits from 8, 7, 5, 3, so 8, 7 and 5 would all be present, and then 7295 would contain three code digits (2, 7, 5), not two. Suppose 9 were in the code: the same argument (6, 3, 2 absent, 8753 forcing 8, 7, 5) gives three code digits 9, 7, 5 in 7295, again a contradiction. So 2 and 9 are absent, and the two correct digits of 7295 are 7 in position 1 and 5 in position 4. Now consider 8354: the 5 is in the code but misplaced (it sits in position 3 there), so its one right-place digit must be 8 in position 1, 3 in position 2 or 4 in position 4. Positions 1 and 4 of the code are already 7 and 5, so it is the 3, in position 2: the code is 7 3 _ 5. The guess 8753 then has code digits 7, 5, 3 (all misplaced), so 8 is absent; 8354 has code digits 3 and 5, so 4 is absent; 6932 has only the 3, so 6 is absent; 3621 has only the 3, so 1 is absent. The last digit has not been excluded only if it is 0. The code is 7305, and a computer search over all 5040 codes confirms it is the only one.
Source: Original puzzle written for AxiomIQ in the style of the code-breaking deduction puzzles popularized by Mastermind-type games.