Enigmatic Code

Programming Enigma Puzzles

Enigma 1114: Christmas changes

From New Scientist #2270, 23rd December 2000 [link]

Christmas is said to change things and so this enigma is an old puzzle with some changes.

Problem: You have to assign a digit to each of the 10 letters in the sum here:

When you have decided on an assignment of digits to the 10 letters, then your assignment is a solution of the problem if it satisfies at least one of the following conditions:

• At least one digit is assigned to more than one letter.
• When the digits are put into the addition sum it is not correct.
• The digit assigned to “U” is smaller than the digit assigned to “H”.

You need to find an assignment of digits to the 10 letters which is NOT a solution of the problem.

What is the value of BLEAT in your assignment?

[enigma1114]

Advertisements

2 responses to “Enigma 1114: Christmas changes

  1. Jim Randell 22 May 2017 at 8:35 am

    We need to find an assignment of digits to letters that is not a solution to the embedded problem.

    So all the listed conditions must be false. i.e. No digits are assigned to more than one letter; and the sum must come out correctly when the digits are substituted in; and the digit assigned to “U” is larger than the digit assigned to “H”.

    In other words this is a straightforward alphametic sum puzzle, so we can use the SubstitutedSum() solver from the enigma.py library, with a check on the solutions to ensure U > H.

    This program runs in 64ms.

    from enigma import SubstitutedSum
    
    SubstitutedSum(["JESUS", "SHEEP"], "STABLE").go(lambda s: s['U'] > s['H'])
    

    Solution: BLEAT = 68570.

    The full sum is:

    95131 + 12554 = 107685

    Without the condition that U > H there is a further solution:

    95121 + 13554 = 108675

    We can also use the generalised alphametic solver (SubstitutedExpression()) that is part of the enigma.py library to save us having to write a program at all. Here’s the run file. It executes in 144ms.

    #!/usr/bin/env python -m enigma -r
    
    SubstitutedExpression
    --answer="BLEAT"
    "JESUS + SHEEP = STABLE"
    "U > H"
    
  2. geoffrounce 21 December 2017 at 2:26 pm
    % A Solution in MiniZinc
    include "globals.mzn";
    
    var 0..9:J;   var 0..9:E;   var 0..9:S;   var 0..9:U;   var 0..9:H; 
    var 0..9:P;   var 0..9:T;   var 0..9:A;   var 0..9:B;   var 0..9:L;
    
    constraint all_different([J, E, S, U, H, P, T, A, B, L])
    /\ J > 0 /\ S > 0 /\ B > 0 /\ U > H;
    
    var 10000..99999: JESUS = 10000*J + 1000*E + 100*S + 10*U + S;
    var 10000..99999: SHEEP = 10000*S + 1000*H + 100*E + 10*E + P;
    var 10000..99999: BLEAT = 10000*B + 1000*L + 100*E + 10*A + T;
    var 100000..999999: STABLE = 100000*S + 10000*T + 1000*A + 100*B + 10*L + E;
    
    constraint JESUS + SHEEP == STABLE /\ U > H;
    
    solve satisfy;
    
    output [ "BLEAT = " ++ show(BLEAT) ]
    ++
    ["\nSum is " ++ show(JESUS) ++ " + " ++ show(SHEEP) ++ " = " ++ show(STABLE) ];
    
    % BLEAT = 68570
    % Sum is 95131 + 12554 = 107685
    % ----------
    % Finished in 85msec
    

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: