Enigmatic Code

Programming Enigma Puzzles

Enigma 391a: Bon-bon time again

From New Scientist #1540, 25th December 1986 [link]

If you can find time between the turkey and the bon-bon, decipher this letter-for-digits long multiplication. As always, digits have been consistently replaced by letters, with different letters replacing different digits throughout.

(You do not need any more clues, but so that you can get it finished before New Year, I can tell you there is no need to be too careful distinction between the letter O and the number 0!)

Find the numerical value of GIFT.

[enigma391a] [enigma391]

Advertisements

2 responses to “Enigma 391a: Bon-bon time again

  1. Jim Randell 7 April 2017 at 8:08 am

    We can use the SubstitutedExpression() solver from the enigma.py library to solve Alphametic problems like this one. Here I introduce the lower-case letters a,b,c,d,e,f,g to stand for the “wildcard” symbols.

    Here is the run file. It executes in 98ms.

    #!/usr/bin/env python -m enigma -r
    
    #       B O N
    #  x    a b c
    #   ---------
    #   B O N
    #   T I M E
    #     d e f g
    #   ---------
    #   A G A I N
    #   =========
    
    SubstitutedExpression
    
    --symbols="ABEFGIMNOTabcdefg"
    --distinct="ABEFGIMNOT"
    --answer="GIFT"
    #--assign="O,0"
    #--assign="a,1"
    
    "BON * abc = AGAIN"
    "BON * a = BON"
    "BON * b = TIME"
    "BON * c = defg"
    

    Solution: GIFT = 9671.

    It is not necessary to use the information that O=0 (although we can add an --assign="O,0" parameter to the run file if we like). Similarly it is quite obvious that a=1. Using both of these restrictions reduces the execution time to 77ms.

  2. geoffrounce 7 April 2017 at 7:16 pm

    I used the same lower case letters and also found the elements of the multiplication sum

    % A Solution in MiniZinc 
    include "globals.mzn";
    
    int: a = 1;  % since BON * a * 100 = BON00
    int: O = 0;
    
    var 0..9:A; var 0..9:B; var 0..9:E; var 0..9:F; 
    var 0..9:G; var 0..9:I; var 0..9:M; var 0..9:N; 
    var 0..9:T; var 0..9:b; var 0..9:c; var 0..9:d;
    var 0..9:e; var 0..9:f; var 0..9:g;
    
    var 100..999: BON = 100*B + 10*O + N;
    var 100..999: abc = 100*a + 10*b + c;
    var 1000..9999: TIME = 1000*T + 100*I + 10*M + E;
    var 1000..9999: GIFT = 1000*G + 100*I + 10*F + T;
    var 1000..9999: defg = 1000*d + 100*e + 10*f + g;
    var 10000..99999: AGAIN = 10000*A + 1000*G + 100*A + 10*I + N;
    
    constraint A > 0  /\ B > 0 /\ G > 0 /\ T > 0 /\ d > 0; 
    
    constraint alldifferent([A,B,E,F,G,I,M,N,T]);
    
    constraint BON * abc = AGAIN /\ BON*a*100 = BON*100 /\ 
    BON*b*10 = TIME*10 /\ BON*c = defg;
    
    solve satisfy;
    
    output[ show(BON) ++ " X " ++ show(abc) ++ " = " ++ 
            show(BON*100) ++ " + " ++ show(TIME*10) ++ " + " ++ show(defg)
            ++ " = " ++ show(AGAIN) ++ "\n" ++ "GIFT = " ++ show(GIFT) ];
           
    % 408 X 146 = 40800 + 16320 + 2448 = 59568
    % GIFT = 9671
    % Finished in 82msec
    
    

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: