**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]

### Like this:

Like Loading...

*Related*

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 🙂