Enigmatic Code

Programming Enigma Puzzles

Enigma 250: A couple of sevens

From New Scientist #1397, 16th February 1984 [link] [link]

The following long-division sum with most of the figures missing comes out exactly:

Enigma 250

Find the missing figures.

[enigma250]

3 responses to “Enigma 250: A couple of sevens

  1. Jim Randell 13 January 2015 at 8:40 am

    Another problem that can be fed straight to the [[ SubstitutedDivision() ]] solver from enigma.py.

    This (single statement) program runs in 350ms.

    from enigma import SubstitutedDivision
    
    SubstitutedDivision(
      "7?????", "??",  "?????",
      [("7?", "??", "??"), ("???", "??", "?"), None, ("???", "??", "??"), ("???", "??7", "")],
      { '7': 7 }
    ).go()
    

    Solution: The full sum is 760287 / 33 = 23039.

    Enigma 250 - Solution

    If you like this kind of puzzle you might like to consider a variation on it with the same diagram and following puzzle text:

    “In the following long-division sum most of the figures are missing, and those that are there are wrong. However each incorrect figure stands for the same correct digit each time it occurs. The sum comes out exactly. Find the missing figures”.

    There is a unique solution.

    • Jim Randell 15 July 2017 at 12:27 pm

      With the new [[ SubstitutedDivision() ]] solver (in the latest version of the enigma.py library), this code would look like this:

      from enigma import SubstitutedDivision
      
      SubstitutedDivision(
        "7????? / ?? = ?????",
        ["7? - ?? = ??", "??? - ?? = ?", None, "??? = ?? - ??", "??? - ??7 = 0"],
      ).go()
      

      And it runs in 144ms (so the new solver is faster than the old one).

      Instead of writing a program the arguments can be supplied on the command line, or placed in a run-file:

      #!/usr/bin/env python -m enigma -r
      
      SubstitutedDivision
      
      "7????? / ?? = ?????"
      
      "7? - ?? = ??"
      "??? - ?? = ?"
      ""
      "??? - ?? = ??"
      "??? - ??7 = 0"
      

      Which we can execute like this:

      % python -m enigma -r enigma250.run
      7????? / ?? = ????? (rem 0) [7? - ?? = ??, ??? - ?? = ?, None, ??? - ?? = ??, ??? - ??7 = 0]
      760287 / 33 = 23039 (rem 0) [76 - 66 = 10, 100 - 99 = 1, None, 128 - 99 = 29, 297 - 297 = 0]
      [1 solution]
      

      By replacing the digit 7 in the puzzle by X we can get the solutions to both the puzzle and it’s variation:

      #!/usr/bin/env python -m enigma -r
      
      SubstitutedDivision
      
      "X????? / ?? = ?????"
      
      "X? - ?? = ??"
      "??? - ?? = ?"
      ""
      "??? - ?? = ??"
      "??? - ??X = 0"
      

      If we run it like this we get both possible values for X:

      % python -m enigma -r enigma250var.run
      X????? / ?? = ????? (rem 0) [X? - ?? = ??, ??? - ?? = ?, None, ??? - ?? = ??, ??? - ??X = 0]
      430254 / 33 = 13038 (rem 0) [43 - 33 = 10, 100 - 99 = 1, None, 125 - 99 = 26, 264 - 264 = 0] / X=4
      760287 / 33 = 23039 (rem 0) [76 - 66 = 10, 100 - 99 = 1, None, 128 - 99 = 29, 297 - 297 = 0] / X=7
      [2 solutions]
      

      Or we can provide additional command line arguments to solve the main puzzle (where X should be 7):

      % python -m enigma -r enigma250var.run --assign="X,7"
      X????? / ?? = ????? (rem 0) [X? - ?? = ??, ??? - ?? = ?, None, ??? - ?? = ??, ??? - ??X = 0]
      760287 / 33 = 23039 (rem 0) [76 - 66 = 10, 100 - 99 = 1, None, 128 - 99 = 29, 297 - 297 = 0] / X=7
      [1 solution]
      

      or the variation (where X cannot be 7):

      % python -m enigma -r enigma250var.run --invalid="7,X"
      X????? / ?? = ????? (rem 0) [X? - ?? = ??, ??? - ?? = ?, None, ??? - ?? = ??, ??? - ??X = 0]
      430254 / 33 = 13038 (rem 0) [43 - 33 = 10, 100 - 99 = 1, None, 125 - 99 = 26, 264 - 264 = 0] / X=4
      [1 solution]
      
  2. geoffrounce 31 August 2017 at 1:57 pm

    I looked at a programme for all solutions where either of the two ‘seven’ digits were different to 7.

    I found (4,2), (4,5), (4,8), (4,1), and (4,4) as answers – the latter being Jim’s solution to the extra puzzle he set. A typical solution is set out in the code below and all solutions are given after the programme code.

    % Enigma 250 - Extra puzzle - and variations
    
    % A Solution in MiniZinc
    % Note: x and t are equal to 7 in the original puzzle, and 4 and 2 below.
    %
    %        Letters         Typical Answer
    %                           
    %        C D E F G          1 3 0 3 4
    %     ------------       ------------
    %  A B)x H I J K L    3 3)4 3 0 1 2 2
    %      a b                3 3
    %      ---                ---
    %      c d I              1 0 0                
    %        e f                9 9
    %        ----             -----
    %          g J K              1 1 2  
    %            l m                9 9
    %            -----              -----
    %            n p L              1 3 2
    %            r s t              1 3 2
    %            =====              =====
    
    include "globals.mzn";
    
    set of int: Digit = 0..9;
    
    var Digit: a;  var Digit: b;  var Digit: c;  var Digit: d; 
    var Digit: e;  var Digit: f;  var Digit: g;  var Digit: l;
    var Digit: m;  var Digit: n;  var Digit: p;  var Digit: r;
    var Digit: s;  var Digit: t;  var Digit: x;  
    
    var Digit: A;  var Digit: B;  var Digit: C;  var Digit: D; 
    var Digit: E;  var Digit: F;  var Digit: G;  var Digit: H; 
    var Digit: I;  var Digit: J;  var Digit: K;  var Digit: L; 
    
    % make 2 digits in original puzzle not equal to 7
    constraint x != 7 /\ t != 7; 
    
    % leading digits which cannot be zero
    constraint A != 0 /\ C != 0 /\ a != 0 /\ c != 0 /\ e != 0 
    /\ g != 0 /\ l != 0 /\ n != 0 /\ r != 0; 
    
    var 10..99: AB = 10*A + B;
    var 10000..99999: CDEFG = 10000*C + 1000*D + 100*E + 10*F + G;
    var 100000..999999: xHIJKL = 100000*x + 10000*H + 1000*I + 100*J + 10*K + L;
    var 10..99 : ab = 10*a + b;
    var 100..999: cdI = 100*c + 10*d + I;
    var 10..99: ef = 10*e + f;
    var 100..999: gJK = 100*g + 10*J + K;
    var 10..99: lm = 10*l + m;
    var 100..999: npL = 100*n + 10*p + L;
    var 100..999: rst = 100*r + 10*s + t;
    var 10..99: cd = 10*c + d;
    var 10..99: xH = 10*x + H;
    var 10..99:np = 10*n + p;
    
    % main division - needed to constrain output to 5 answers
    % there are multiple repeared answers without this constraint
    constraint AB * CDEFG == xHIJKL;
    
    % multiplications
    constraint C * AB == ab;
    constraint D * AB == ef;
    constraint F * AB == lm;
    constraint G * AB == rst;
    
    % subtractions
    constraint xH - ab == cd;
    constraint cdI - ef == g;
    constraint gJK - lm == np;
    constraint npL - rst == 0;
    
    solve satisfy;
    output ["Sum: " ++ show(xHIJKL) ++ " / " ++ show(AB) ++ " = " ++ show (CDEFG) ]
        ++ ["\nab = " ++ show(ab) ++ " cdI = " ++ show(cdI) ++ "\n" ++
           "ef = " ++ show(ef) ++ "  gJK = " ++ show(gJK) ++ "\n" ++
           "lm = " ++ show(lm) ++ "  npL = " ++ show(npL) ++ " rst = " ++ show(rst) ];
           
    % OUTPUT
    % 1) ----Two digits are 4 and 2
    % Sum: 430122 / 33 = 13034
    % ab = 33 cdI = 100
    % ef = 99  gJK = 112
    % lm = 99  npL = 132 rst = 132
    
    % 2) ----Two digits are 4 and 5
    % Sum: 430155 / 33 = 13035
    % ab = 33 cdI = 100
    % ef = 99  gJK = 115
    % lm = 99  npL = 165 rst = 165
    
    % 3) ---Two digits are 4 and 8
    % Sum: 430188 / 33 = 13036
    % ab = 33 cdI = 100
    % ef = 99  gJK = 118
    % lm = 99  npL = 198 rst = 198
    
    % 4) -- Two digits are 4 and 1
    % Sum: 430221 / 33 = 13037
    % ab = 33 cdI = 100
    % ef = 99  gJK = 122
    % lm = 99  npL = 231 rst = 231
    
    % 5)----Two digits are 4 and 4 (Jim's solution)
    % Sum: 430254 / 33 = 13038
    % ab = 33 cdI = 100
    % ef = 99  gJK = 125
    % lm = 99  npL = 264 rst = 264
    % ----------
    % ========== indicates no more solutions
    % Finished in 72msec
    
    

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.