Enigmatic Code

Programming Enigma Puzzles

Enigma 245: Reflected Enigma

From New Scientist #1392, 12th January 1984 [link]

In this puzzle, as usual, different symbols stand consistently for different digits. You might like to reflect on the following multiplication and subtraction sums:

Enigma 245 - 1

Of course things don’t always work out like that: sometimes one sees double!:

Enigma 245 - 2

Given all the equations, what is ENIGMA?

[enigma245]

Advertisements

2 responses to “Enigma 245: Reflected Enigma

  1. Jim Randell 23 December 2014 at 8:05 am

    This Python program runs in 32ms, which is quite a lot faster than just considering all possible permutations.

    from itertools import permutations
    from enigma import irange, nconcat, printf
    
    # using lower case to indicate reflected letters
    
    digits = set(irange(0, 9))
    
    # N = n + n
    for n in digits:
      N = n + n
      # IN = nI + nI
      (I, r) = divmod(20 * n - N, 8)
      if r > 0: continue
      ds1 = digits.difference([n, N, I])
      if len(ds1) != 7: continue
    
      # E - N - M = M - n - e
      for (E, M) in permutations(ds1, 2):
        e = M + N + M - E - n
        ds2 = ds1.difference([E, M, e])
        if len(ds2) != 4: continue
    
        # ENIG x MA = AM x gIne
        for (G, g) in permutations(ds2, 2):
          ENIG = nconcat(E, N, I, G)
          gIne = nconcat(g, I, n, e)
          (A, r) = divmod(M * (10 * ENIG - gIne), 10 * gIne - ENIG)
          if r > 0: continue
          ds3 = ds2.difference([G, g, A])
          if len(ds3) != 1: continue
    
          printf("ENIGMA={ENIG}{M}{A} [N={N} n={n} I={I} E={E} M={M} e={e} A={A} G={G} g={g}]")
    

    Solution: ENIGMA = 689512.

    The remaining letters are: n = 4, e = 0, g = 3.

  2. geoffrounce 23 December 2014 at 10:29 am

    I got the same answer and tried splitting up the permutations to speed up my code.
    I also used your idea of lower case letters for reflected capital letters.

    from itertools import permutations
    for p in permutations('9876543210',3):
      if any(z == '0' for z in ('E','M','A','g','N','n','I')): continue
      I,N,n = p
      if int(N) != 2 * int(n) :continue
      if int(I+N) != 2 * int(n + I): continue
      digits = set('9876543210').difference(set((str(I),str(N),str(n))))
      for q in permutations(digits,6):
        E,G,M,A,g,e = q
        if int(E) - int(N) - int(M) != int(M) - int(n) - int(e) : continue
        if int(E + N + I + G) * int(M + A) == int(A + M) * int(g + I + n + e):
          ENIGMA = int(E + N + I + G + M + A)
          print('ENIGMA =', ENIGMA)
    

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: