Enigmatic Code

Programming Enigma Puzzles

Enigma 1648: Enigmarred

From New Scientist #2814, 28th May 2011 [link]

Below I have listed seven numbers, but I have coded them by consistently replacing digits with letters, with different letters used for different digits:

CINEMA
ECZEMA
EMMA
ENEMA
ENIGMA
MAMMA
STIGMA

All but one of the seven numbers is divisible by 9.

Which word represents the number which is not divisible by 9?

[enigma1648]

Advertisements

2 responses to “Enigma 1648: Enigmarred

  1. Jim Randell 6 December 2011 at 6:30 pm

    The following Python code runs in 49ms.

    from itertools import permutations
    from enigma import printf
    
    # how many things in the list are not multiples of nine
    def n9(*s):
      return len(filter(lambda n: n % 9 > 0, s))
    
    d = set(range(10))
    for (A, E, M) in permutations(d, 3):
      if 0 in (E, M): continue
      EMMA = E * 1000 + M * 110 + A
      MAMMA = M * 10110 + A * 1001
      if n9(EMMA, MAMMA) > 1: continue
    
      d1 = d.difference([A, E, M])
      EMA = 100 * E + 10 * M + A
      for N in d1:
        NEMA = N * 1000 + EMA
        ENEMA = E * 10000 + NEMA
        if n9(EMMA, MAMMA, ENEMA) > 1: continue
    
        d2 = d1.difference([N])
        for (C, I) in permutations(d2, 2):
          if C == 0: continue
          CINEMA = C * 100000 + I * 10000 + NEMA
          if n9(EMMA, MAMMA, ENEMA, CINEMA) > 1: continue
    
          d3 = d2.difference([C, I])
          for Z in d3:
            ECZEMA = E * 100000 + C * 10000 + Z * 1000 + EMA
            if n9(EMMA, MAMMA, ENEMA, CINEMA, ECZEMA) > 1: continue
    
            d4 = d3.difference([Z])
            for G in d4:
              IGMA = I * 1000 + G * 100 + M * 10 + A
              ENIGMA = E * 100000 + N * 10000 + IGMA
              if n9(EMMA, MAMMA, ENEMA, CINEMA, ECZEMA, ENIGMA) > 1: continue
    
              d5 = d4.difference([G])
              for (S, T) in permutations(d5, 2):
                if S == 0: continue
                STIGMA = S * 100000 + T * 10000 + IGMA
                if n9(EMMA, MAMMA, ENEMA, CINEMA, ECZEMA, ENIGMA, STIGMA) != 1: continue
    
                s = (EMMA, MAMMA, ENEMA, CINEMA, ECZEMA, ENIGMA, STIGMA)
                i = filter(lambda i: s[i] % 9 > 0, range(len(s)))
                n = ('EMMA', 'MAMMA', 'ENEMA', 'CINEMA', 'ECZEMA', 'ENIGMA', 'STIGMA')[i[0]]
                printf("{n} {s}")
    

    Solution: ENEMA is not divisible by 9.

    There are 12 different ways of assigning digits to the letters, but in all cases ENEMA is the only number not divisible by 9.

    Here are the 12 assignments:

    A=6 C=9 E=2 G=0 I=1 M=5 N=4 S=7 T=8 Z=3
    A=6 C=9 E=2 G=0 I=1 M=5 N=4 S=8 T=7 Z=3
    A=3 C=9 E=4 G=0 I=2 M=1 N=8 S=5 T=7 Z=6
    A=3 C=9 E=4 G=0 I=2 M=1 N=8 S=7 T=5 Z=6
    A=6 C=9 E=8 G=0 I=4 M=2 N=7 S=1 T=5 Z=3
    A=6 C=9 E=8 G=0 I=4 M=2 N=7 S=5 T=1 Z=3
    A=3 C=9 E=1 G=0 I=5 M=7 N=2 S=4 T=8 Z=6
    A=3 C=9 E=1 G=0 I=5 M=7 N=2 S=8 T=4 Z=6
    A=6 C=9 E=5 G=0 I=7 M=8 N=1 S=2 T=4 Z=3
    A=6 C=9 E=5 G=0 I=7 M=8 N=1 S=4 T=2 Z=3
    A=3 C=9 E=7 G=0 I=8 M=4 N=5 S=1 T=2 Z=6
    A=3 C=9 E=7 G=0 I=8 M=4 N=5 S=2 T=1 Z=6

    • Jim Randell 7 August 2017 at 10:49 am

      We can use the SubstitutedExpression() solver from the enigma.py library to find the solution to the puzzle and output the list of numbers and assignments neatly using a short run file. Execution time however is 2.5s (using PyPy).

      #!/usr/bin/python -m enigma -r
      
      SubstitutedExpression
      --template="1. CINEMA  2. ECZEMA  3. EMMA  4. ENEMA  5. ENIGMA  6. MAMMA  7. STIGMA"
      --answer="tuple(i for (i, x) in enumerate([CINEMA, ECZEMA, EMMA, ENEMA, ENIGMA, MAMMA, STIGMA], start=1) if x % 9 > 0)"
      
      "sum(x % 9 > 0 for x in [CINEMA, ECZEMA, EMMA, ENEMA, ENIGMA, MAMMA, STIGMA]) == 1"
      

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: