Enigmatic Code

Programming Enigma Puzzles

Enigma 1647: Fifth-division clincher

From New Scientist #2813, 21st May 2011 [link]

ENIGMA is a six-digit number in which all the digits are different and non-zero. When ENIGMA is divided by 19, or 17, or 13, or 11, or G, the remainders are, respectively, 17, 13, 11, 7 and I (I as in India).

Find ENIGMA.

[enigma1647]

Advertisements

2 responses to “Enigma 1647: Fifth-division clincher

  1. Jim Randell 7 December 2011 at 9:48 am

    A little bit of analysis yields this program, which runs in 30ms:

    # consider ENIGMA + 2, it must be a factor of 19 and 13 (247)
    # and ENIGMA + 4 must be a factor of 17 and 11 (187)
    
    for ENIGMA2 in range(100035, 1000103, 247):
      ENIGMA4 = ENIGMA2 + 2
      if ENIGMA4 % 187 > 0: continue
      ENIGMA = ENIGMA2 - 2
      # split it into digits
      s = str(ENIGMA)
      d = set(s)
      if len(d) != 6: continue
      if '0' in d: continue
      if ENIGMA % int(s[3]) != int(s[2]): continue
      print("ENIGMA =", ENIGMA)
    

    and it produces the same result as this more straightforward approach (which has a runtime of 200ms):

    from itertools import permutations
    
    for x in permutations(range(1, 10), 6):
      ENIGMA = int(''.join(map(str, x)))
      if ENIGMA % 19 != 17: continue
      if ENIGMA % 17 != 13: continue
      if ENIGMA % 13 != 11: continue
      if ENIGMA % 11 !=  7: continue
      if ENIGMA % x[3] != x[2]: continue
      print("ENIGMA =", ENIGMA)
    

    Solution: ENIGMA = 943785.

  2. geoffrounce 22 March 2018 at 8:56 am
    % A MiniZinc solution
    include "globals.mzn";
    
    var 1..9:E; var 1..9:N; var 1..9:I; var 1..9:G; var 1..9:M; var 1..9:A; 
    
    constraint all_different([E, N, I, G, M, A]);
    
    var 100000..999999: ENIGMA = 100000*E + 10000*N + 1000*I + 100*G + 10*M + A;
    
    constraint ENIGMA mod 19 == 17 /\ ENIGMA mod 17 == 13
    /\ ENIGMA mod 13 == 11 /\ ENIGMA mod 11 == 7 /\ ENIGMA mod G == I;
    
    solve satisfy;
    output [ "ENIGMA = " ++ show(ENIGMA)];   
    
    % ENIGMA = 943785
    % Finished in 767msec
    

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: