Enigmatic Code

Programming Enigma Puzzles

Enigma 1681: Twins divide

From New Scientist #2848, 21st January 2011 [link]

My niece, Angela, has two younger twin siblings, Ann and Ian. To celebrate the twins’ birthday, she asked me to compose a puzzle in which their names feature. Here it is:

With different letters denoting different digits consistently throughout, and with no leading zeros appearing, the number denoted by GEMINI is exactly divisible by the numbers corresponding to ANN and IAN. These two three-digit numbers have no common factor. The number denoted by ANGIE has digits which increase from left to right.

What number corresponds to ENIGMA?

[enigma1681]

Advertisements

3 responses to “Enigma 1681: Twins divide

  1. jimrandell 18 January 2012 at 6:55 pm

    The following Python program runs in 31ms.

    from enigma import irange, concat, factor, printf
    
    # digits
    d1 = set(irange(0, 9))
    
    # A < N < G < I < E
    # and:
    # ANN and IAN share no common factors (so N cannot be even, or 5)
    
    # so:
    # A in 1, 2
    # N is 3
    # G in 4, 5, 6, 7
    # I in 5, 6, 7, 8
    # E in 6, 7, 8, 9
    
    N = 3
    for A in (1, 2):
      ANN = int(concat(A, N, N))
      for I in (x for x in (5, 6, 7, 8) if N + 1 < x):
        IAN = int(concat(I, A, N))
        if set(factor(ANN)).intersection(factor(IAN)): continue
    
        for G in (x for x in (4, 5, 6, 7) if N < x < I):
          for E in (x for x in (6, 7, 8, 9) if I < x):
            for M in d1.difference((A, N, G, I, E)):
              GEMINI = int(concat(G, E, M, I, N, I))
              if GEMINI % ANN or GEMINI % IAN: continue
    
              ENIGMA = concat(E, N, I, G, M, A)
    
              printf("ENIGMA={ENIGMA} [ANN={ANN} IAN={IAN} GEMINI={GEMINI}]")
    

    Solution: ENIGMA = 836502.

    • geoffRounce 4 August 2016 at 11:23 am
      from itertools import permutations
      from math import gcd
      
      for p in permutations('9876543210',6):
        e, n, i, g, m, a = p
        if int(a) < int(n) < int(g) < int(i) < int(e):
          angie = int(a + n + g + i + e)
          gemini = int(g + e + m + i + n + i)
          ann = int(a + n + n)
          ian = int(i + a + n)
          
          if gemini % ann == 0 and gemini % ian == 0:
            if gcd(ann,ian) == 1:
              enigma = int(e + n + i + g + m + a)
              fs = 'ENIGMA = {}, ANN = {}, IAN = {}, GEMINI = {}, ANGIE = {}'
              print(fs.format(enigma,ann,ian,gemini,angie))
              
      # ENIGMA = 836502, ANN = 233, IAN = 623, GEMINI = 580636, ANGIE = 23568  
      
  2. Jim Randell 4 August 2016 at 1:08 pm

    This problem can be solved using the command line Alphametic solver (SubstitutedExpression) in the enigma.py library, without the need to write a program. The command runs in 74ms.

    % python -m enigma SubstitutedExpression \
        --answer="ENIGMA" \
        "GEMINI % ANN = 0" \
        "GEMINI % IAN = 0" \
        "gcd(ANN, IAN) = 1" \
        "A < N < G < I < E"
    (GEMINI % ANN = 0) (GEMINI % IAN = 0) (gcd(ANN, IAN) = 1) (A < N < G < I < E)
    (580636 % 233 = 0) (580636 % 623 = 0) (gcd(233, 623) = 1) (2 < 3 < 5 < 6 < 8) / A=2 E=8 G=5 I=6 M=0 N=3 / 836502
    ENIGMA = 836502 [1 solution]
    

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: