### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,158)
- misc (2)
- project euler (2)
- puzzle (40)
- site news (44)
- tantalizer (42)
- teaser (3)

### Site Stats

- 178,002 hits

Advertisements

Programming Enigma Puzzles

28 March 2012

Posted by on **From New Scientist #2858, 31st March 2012** [link]

The number 3120 is divisible without remainder by each number in the following set: 3, 312, 12, 120, 2 and 20. Each of these numbers will be called a visible proper divisor (VPD) of 3120 because each is visible either as a single digit or as a group of adjacent digits in 3120. (1 and 3120 have been excluded as being improper, in order that any prime number has no VPDs).

ENIGMA represents an odd six-digit number in which all the digits are different. The set of all VPDs of ENIGMA is E, NI, IG, G, GMA, M, MA, and A. What is ENIGMA?

[enigma1691]

Advertisements

%d bloggers like this:

Here’s my first attempt in Python. It runs in 1.7s.

Solution:ENIGMA = 921375.As 1 is not allowed as a VPD, we can ignore cases where one of E, G, M, A is 1. This version runs in 794ms (and gives the same answer).

Here’s a version that sets up the indices of substrings that are VPDs, and those that aren’t VPDs. It runs in 135ms.

Here is my version:

Your analysis massively reduces the search space to only 96 cases, only one of which has all of the required VPDs. Although I think it is still necessary to check that that candidate has no other VPDs to strictly satisfy the conditions of the question.

Here’s my final code. It executes in 37ms.

If I had got more than one solution, I would have done so 🙂

A brute force programme in MiniZinc took 2 sec.

Here’s a full solution using the

SubstitutedExpression()solver from theenigma.pylibrary (which I hadn’t written at the time I posted the puzzle).It executes in 205ms.

Run:[ @repl.it ]The fact that ENIGMA is odd is not necessary to solve the puzzle, but this fact along with the conditions that E, NI and IG divide ENIGMA are enough to narrow the answer down to a single possibility.