Spoiler for New Scientist Enigma 1691:

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?

If ENIGMA is odd, then so are all its factors. This means E, I, G, M, and A must be odd digits. None but I can be 1 (the rest must be proper factors). ENIGMA is divisible by 5, so A must be 5. The other three must be 3, 7, and 9.

ENIGMA is divisible by 9, so its digits must sum to a multiple of 9. The sum is 1+3+5+7+9+N = 25+N, so N must be 2.

There are then six possibilities of the form E21GM5. Of these only one, 921375, is divisible by 7. Of course it is also divisible by NI = 21 since it’s divisible by 3. It’s obviously divisible by 25 and divisibility by 3 means it’s divisible by MA = 75. We have to check separately for IG = 13 and GMA = 375. It passes.

### Like this:

Like Loading...

I like the logic you used to solve the problem. When I read “The set of all VPDs of ENIGMA” I had thought there would be more solutions, that the non-VPDs would need to be used, i.e. IGM, NIG, …, but no.

I like your solution very much. Anyways, using brute force:

#include

int isfactor(int num, int factor);

int isfactor(int num, int factor)

{

if ( (factor == 0) || (factor == 1) )

return 0;

if ( (num % factor) == 0)

return 1;

else return 0;

}

int main (int argc, const char * argv[]) {

for (int e = 0; e<10; e++) // e

{

for (int n = 0; n<10; n++) // n

{

printf("Scanning %d\n", e*100000 + n*10000 );

if (n == e)

continue;

for (int i = 0; i<10; i++) // i

{

if ( (i == e) || (i == n) )

continue;

for (int g = 0; g<10; g++) // g

{

if ( (g == e) || (g == n) || (g == i) )

continue;

for (int m = 0; m<10; m++) // m

{

if ( (m == e) || (m == n) || (m == i) || (m == g) )

continue;

for (int a = 0; a<10; a++) // a

{

if ( (a == e) || (a == n) || (a == i) || (a == g) || (a == m) )

continue;

int number = ((((((((e*10 + n) * 10) + i) * 10) + g) * 10) + m) * 10) + a;

// E NI IG G GMA M MA A

// E

if (!isfactor( number, e) )

continue;

// NI

if (!isfactor( number, n*10+i) )

continue;

// IG

if (!isfactor( number, i*10+g) )

continue;

// G

if (!isfactor( number, g) )

continue;

// GMA

if (!isfactor( number, (g*10+m) * 10 + a) )

continue;

// M

if (!isfactor( number, m) )

continue;

// MA

if (!isfactor( number, m*10 + a) )

continue;

// A

if (!isfactor( number, a) )

continue;

printf("could be: %d %2d%2d%2d%2d%2d%2d \n", number, e, n, i, g, m, a);

}

}

}

}

}

}

printf("Hello, World!\n");

return 0;

}

LikeLike