**From New Scientist #1038, 10th February 1977** [link]

If you look up the phone number of Sir William Watergate in the book, you will not find it. He is ex-directory. But you can work it out from the list of ten numbers below. Each of the ten has exactly one of Sir William’s digits correctly placed. Consider the first number, 14073, for instance. It implies that Sir William is not on 14257, which would mean two digits correctly placed, nor on 40731, which would mean none.

14073

29402

35862

42936

50811

63136

79588

84771

98174

07145

If I just add that Sir William’s true number has five digits, can you discover it?

[tantalizer487]

### Like this:

Like Loading...

This brute force program is quite short and runs in 459ms.

Solution:The phone number is 09876.We can also use the alphametic solver (

SubstitutedExpression()) from theenigma.pylibrary to solve this puzzle.This run file executes in 216ms.

(The digits are not necessarily distinct, and leading zeros are allowed).

Expressing a similar set of constraints in MiniZinc allows several of the MiniZinc solvers to find a solution in 65-69ms.

This reminds me of the game marketed as Mastermind.

Ten incorrect numbers seems a lot, to be able to deduce five digits.

Could it have been solved with fewer numbers given?

Certainly I noticed when solving the problem that the final candidate (07145) is not required, as we have already got down to a single unique solution with the first nine candidates. So they are not all required.

In fact 9 in the minimum number of candidates required. We can do without exactly one of: 35862, 84771, 98174, 07145.

Enigma 52is anotherMastermindtype of puzzle.Using profile based timing, this version runs in 90ms on my laptop.

@Brian: For comparison purposes the total run time of this program is 201ms in my environment.

Using the telephone numbers in the order listed as num1 to num10 in the code below,

it looks as though the correct digit in the correct position is not unique in four of the five digits

– as identified in the extra comments at the end of my code.

To complicate things further, the correct digit also appears in two or three incorrect positions in all five digits.

Here’s my interpretation of the problem using MiniZinc. I get a 65ms run time using

mzn-g12fd -a.