Enigmatic Code

Programming Enigma Puzzles

Enigma 1139: A simple addition

From New Scientist #2295, 16th June 2001 [link]

enigma-1139

The simple addition, 0 + 2 + 7 + 11 = 20, may also be written as shown in the diagram where different letters stand for different digits and the same letter stands for the same digit.

What is the value of NIL?

[enigma1139]

Advertisements

2 responses to “Enigma 1139: A simple addition

  1. Jim Randell 28 November 2016 at 6:16 am

    You can use the SubstitutedSum() solver from the enigma.py library:

    % python -m enigma SubstitutedSum "NIL + TWO + SEVEN + ELEVEN = TWENTY" 
    (NIL + TWO + SEVEN + ELEVEN = TWENTY)
    (617 + 904 + 28586 + 878586 = 908693) / E=8 I=1 L=7 N=6 O=4 S=2 T=9 V=5 W=0 Y=3
    

    or the general SubstitutedExpression() solver:

    % python -m enigma SubstitutedExpression --answer="NIL" "NIL + TWO + SEVEN + ELEVEN = TWENTY" 
    (NIL + TWO + SEVEN + ELEVEN = TWENTY)
    (617 + 904 + 28586 + 878586 = 908693) / E=8 I=1 L=7 N=6 O=4 S=2 T=9 V=5 W=0 Y=3 / 617
    NIL = 617 [1 solution]
    

    although neither is particularly quick (799ms for SubstitutedSum(), 1.17s for SubstitutedExpression()).

    Solution: NIL = 617.

    When the solution was originally published in New Scientist #2301 a solution of NIL = 61 was given. A correction to this was published in New Scientist #2304 giving the correct answer.

    With a bit more work we can reduce the run-time for the SubstitutedExpression() solver to a more reasonable 110ms by splitting out the columns as individual sums and including additional symbols (abcde) for the carries (which have a limited set of values). This gives the heuristic algorithm a chance to decide the order in which to consider the columns (instead of the simple right-to-left evaluation done by the SubstitutedSum() solver).

    If we wanted to, we could specify expressions in the order we wanted them to be evaluated in, and then pass the “--reorder=0” flag as a solver parameter to tell the solver to consider them in the order specified.

    The lion’s share of the 110ms spent by the SubstitutedExpression() solver is in the creation and compilation of the specialised Python program to solve the problem. The actual internal runtime of the specialised program (after compilation) is only 9ms.

    Here is the appropriate run file:

    #!/usr/bin/env python -m enigma -r
    
    # solver to use
    SubstitutedExpression
    
    # solver parameters
    --symbols="EILNOSTVWYabcde"
    --distinct="EILNOSTVWY"
    --answer="NIL"
    --invalid="0,ENST"
    --invalid="456789,abcde"
    --invalid="3,de"
    --invalid="2,e"
    
    # the columns of the sum
    "L + O + N + N = aY"
    "I + W + E + E + a = bT"
    "N + T + V + V + b = cN"
    "E + E + c = dE"
    "S + L + d = eW"
    "E + e = T"
    
  2. Naim Uygun 29 November 2016 at 10:39 am

    http://www.iread.it/cryptarithms.php
    NIL+TWO+SEVEN+ELEVEN=TWENTY
    Solution:
    L O N Y I T W S E V
    7 4 6 3 1 9 0 2 8 5

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: