Enigmatic Code

Programming Enigma Puzzles

Enigma 44: Letters for multiplication

From New Scientist #1186, 20th December 1979 [link]

In the multiplication sum below, the digits have been replaced by letters. The same letter stands for the same digit wherever it appears, and different letters stand for different digits.

Enigma 44

Write the sum out with letters replaced by digits.



2 responses to “Enigma 44: Letters for multiplication

  1. jimrandell 29 January 2012 at 8:03 pm

    The following Python program runs in 95ms.

    from itertools import permutations
    from enigma import irange, concat, split, printf
    for (R, E, M, H, B) in permutations(irange(0, 9), 5):
      if not(0 < R < 5 and M > 1): continue
      REMHB = int(concat(R, E, M, H, B))
      TMGBR = str(REMHB * M)
      if len(TMGBR) != 5: continue
      (T, m, G, b, r) = split(TMGBR, int)
      if not(m == M and b == B and r == R): continue
      if len(set((R, E, M, H, B, T, G))) != 7: continue
      printf("{REMHB} x {M} = {TMGBR}")

    Solution: 46287 × 2 = 92574.

  2. Jim Randell 8 January 2013 at 2:26 pm

    Treating the multiplication as repeated addition and using the SubstitutedSum() solver from the enigma.py module we can use the following Python program to solve this Enigma in 44ms.

    from enigma import irange, SubstitutedSum
    ds = set(irange(0, 9))
    # M is a single digit, and not 0 or 1
    for M in irange(2, 9):
      # treat the multiplication as repeated addition
      p = SubstitutedSum(['REMHB'] * M, 'TMGBR', digits=ds.difference([M]), l2d={ 'M': M })
      for r in p.solve():
        print(p.substitute(r, "REMHB x M = TMGBR"))

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: