Enigmatic Code

Programming Enigma Puzzles

Enigma 318: Letters upon letters

From New Scientist #1466, 25th July 1985 [link]

Below is an addition sum with letters substituted for digits. The same letter stands for the same digit wherever it appears, and different letters stand for different digits.

Enigma 318

Write out the sum with numbers substituted for letters.

[enigma318]

Advertisements

5 responses to “Enigma 318: Letters upon letters

  1. Jim Randell 6 November 2015 at 7:40 am

    Another puzzle that can easily be solved by the SubstitutedSum() solver in enigma.py.

    This Python program runs in 83ms.

    from enigma import SubstitutedSum
    
    SubstitutedSum(['ZKDMZ', 'DELEZ', 'MLQMZ', 'DGEMZ'], 'YKZXD').go()
    

    Solution: The sum is: 36213 + 24043 + 10713 + 25413 = 96382.

    Enigma 318 - Solution

    • geoffrounce 6 November 2015 at 10:59 am

      A solution in MiniZinc:

      include "globals.mzn";
       
      % range of variables allows for non leading zeros in the sum
      var 1..9:Z;   var 0..9:K;  var 1..9:D;
      var 1..9:M;   var 0..9:E;  var 0..9:L;
      var 0..9:G;   var 1..9:Y;  var 0..9:X;
      var 0..9:Q;
      
      constraint 
           alldifferent([Z,K,D,M,E,L,G,Y,X,Q]);
      
      constraint
           (Z*10000 + K*1000 + D*100 + M*10 + Z) +
           (D*10000 + E*1000 + L*100 + E*10 + Z) +
           (M*10000 + L*1000 + Q*100 + M*10 + Z) +
           (D*10000 + G*1000 + E*100 + M*10 + Z) =
           (Y*10000 + K*1000 + Z*100 + X*10 + D);
      
      solve satisfy;
      
      output [show(Z),show(K),show(D),show(M),show(Z)," + ",
              show(D),show(E),show(L),show(E),show(Z)," + ",
              show(M),show(L),show(Q),show(M),show(Z)," + ",
              show(D),show(G),show(E),show(M),show(Z)," = ",
              show(Y),show(K),show(Z),show(X),show(D)];
      
      % Output
      % 36213 + 24043 + 10713 + 25413 = 96382
      
    • Jim Randell 2 September 2016 at 9:16 pm

      Or, using the command-line version of the SubstitutedSum() solver from enigma.py – here’s the command and its output:

      % python -m enigma SubstitutedSum "ZKDMZ + DELEZ + MLQMZ + DGEMZ = YKZXD"
      (ZKDMZ + DELEZ + MLQMZ + DGEMZ = YKZXD)
      (36213 + 24043 + 10713 + 25413 = 96382) / D=2 E=4 G=5 K=6 L=0 M=1 Q=7 X=8 Y=9 Z=3
      
  2. Hugh Casement 6 November 2015 at 8:33 am

    These substitution puzzles with random jumbles of letters are so unimaginative.  Wouldn’t they be more interesting with real words?  Admittedly, I can’t find words to fit all five numbers, but how about
    D A T E D
    T  I M  I D
    E M B E D
    T R  I E D
    ––––––––
    Z A D U T

    DATED could equally be DOTED, and of course the order of the summands could be varied.

    • Naim Uygun 6 November 2015 at 12:32 pm

      Hi Hugh,
      Yes, yours is better. Here is my Python program for your suggestion:

      from itertools import permutations
      for w in permutations("9876543210",10):    
          d,a,t,e,i,m,b,r,z,u=w
          if '0' in [d,t,e,z] : continue
          if t not in ['2','4','6','8'] : continue
          
          dated=int("".join((d,a,t,e,d)))
          timid=int("".join((t,i,m,i,d)))
          embed=int("".join((e,m,b,e,d)))
          tried=int("".join((t,r,i,e,d)))
      
          s=dated+timid+embed+tried
          zadut=int("".join((z,a,d,u,t)))    
          if s != zadut  :  continue
          #Output: 36213 + 24043 + 10713 + 25413 = 96382
          print(dated,"+",timid,"+",embed,"+",tried,"=",zadut)
      

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: