Enigmatic Code

Programming Enigma Puzzles

Puzzle 76: Addition: letters for digits (one letter wrong)

From New Scientist #1127, 2nd November 1978 [link]

Below is an addition sum with letters substituted for digits. The same letter should stand for the same digit wherever it appears, and different letters should stand for different digits. Unfortunately, however, there has been a mistake and in the third line across one of the letters is incorrect. The sum looks like this:

Which letter was wrong? What should it be? Write out the correct addition sum.

[puzzle76]

Advertisements

One response to “Puzzle 76: Addition: letters for digits (one letter wrong)

  1. Jim Randell 5 April 2017 at 8:28 am

    See also: Enigma 29, Enigma 197, Enigma 284.

    This Python program uses the SubstitutedSum() solver from the enigma.py library. For each letter in the result is creates an alphametic sum where that particular letter is substituted for different symbol. It runs in 427ms.

    from enigma import SubstitutedSum, join, printf
    
    # the incorrect alphametic sum: X + Y = Z
    (X, Y, Z) = ("BRNHKREBL", "BRLHXEBBL", "KKNBLPDLK")
    
    # the symbols used (maybe plus an extra one)
    symbols = join(sorted(set(X + Y + Z)))
    if len(symbols) < 10: symbols += '?'
    
    # one of the letters in Z is wrong
    for (i, z) in enumerate(Z):
      # choose a replacement symbol
      for r in symbols:
        if r == z: continue
        # create a solver for the modified sum
        p = SubstitutedSum([X, Y], Z[:i] + r + Z[i + 1:])
        # and solve it
        for s in p.solve():
          printf("pos {i}, {z}->{r} / {p.text} / {t}", t=p.substitute(s, p.text))
    

    Solution: The second letter from the left in the result of the sum should be an H (not a K). The correct addition sum with digits substituted for letters is: 430783249 + 439712449 = 870495698.

    The correct alphametic sum is: BRNHKREBL + BRLHXEBBL = KHNBLPDLK.

    We can verify the solution directly using the SubstitutedSum() solver from the enigma.py library using the command line:

    % python -m enigma SubstitutedSum "BRNHKREBL + BRLHXEBBL = KHNBLPDLK"
    (BRNHKREBL + BRLHXEBBL = KHNBLPDLK)
    (430783249 + 439712449 = 870495698) / B=4 D=6 E=2 H=7 K=8 L=9 N=0 P=5 R=3 X=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: