Enigmatic Code

Programming Enigma Puzzles

Enigma 1012: Pieces of eight

From New Scientist #2168, 9th January 1999 [link]

In this sum each letter represents a different digit. The same letter represents the same digit wherever it appears and no number starts with a zero.

What is the 5-digit number represented by EIGHT?

News

This is the first puzzle that was published in 1999, so there is now a complete 15 year archive of Enigma puzzles from the start of 1999 to the final Enigma puzzle published in December 2013. There is also a complete 11 year archive of earlier puzzles from October 1977 to January 1989. As well as Tantalizer puzzles from 1976 and 1977. This brings the total number of archived puzzles to over 1400. I will continue to expand the archive by posting puzzles on a regular schedule.

[enigma1012]

2 responses to “Enigma 1012: Pieces of eight

  1. Jim Randell 3 May 2019 at 9:32 am

    We can find the solution directly from the command line using the [[ SubstitutedExpression() ]] solver from the enigma.py library.

    The following command executes in 601ms.

    % python -m enigma SubstitutedExpression "ONE + TWO + FIVE = EIGHT" --answer="EIGHT"
    (ONE + TWO + FIVE = EIGHT) (EIGHT)
    (621 + 846 + 9071 = 10538) (10538) / E=1 F=9 G=5 H=3 I=0 N=2 O=6 T=8 V=7 W=4
    (621 + 876 + 9041 = 10538) (10538) / E=1 F=9 G=5 H=3 I=0 N=2 O=6 T=8 V=4 W=7
    (641 + 826 + 9071 = 10538) (10538) / E=1 F=9 G=5 H=3 I=0 N=4 O=6 T=8 V=7 W=2
    (641 + 876 + 9021 = 10538) (10538) / E=1 F=9 G=5 H=3 I=0 N=4 O=6 T=8 V=2 W=7
    (671 + 826 + 9041 = 10538) (10538) / E=1 F=9 G=5 H=3 I=0 N=7 O=6 T=8 V=4 W=2
    (671 + 846 + 9021 = 10538) (10538) / E=1 F=9 G=5 H=3 I=0 N=7 O=6 T=8 V=2 W=4
    EIGHT = 10538 [6 solutions]
    

    Solution: EIGHT = 10538.

    The N, W, V (tens) column consists of 2, 4, 7 in some order. This gives rise to the six possible solutions.

    For a faster solution we use the [[ SubstitutedSum() ]] solver to find the six sums. This is faster, but it lacks the grouping provided by the [[ --answer ]] parameter to the [[ SubstitutedExpression() ]] solver.

    % python -m enigma SubstitutedSum "ONE + TWO + FIVE = EIGHT"
    (ONE + TWO + FIVE = EIGHT)
    (621 + 846 + 9071 = 10538) / E=1 F=9 G=5 H=3 I=0 N=2 O=6 T=8 V=7 W=4
    (621 + 876 + 9041 = 10538) / E=1 F=9 G=5 H=3 I=0 N=2 O=6 T=8 V=4 W=7
    (641 + 826 + 9071 = 10538) / E=1 F=9 G=5 H=3 I=0 N=4 O=6 T=8 V=7 W=2
    (641 + 876 + 9021 = 10538) / E=1 F=9 G=5 H=3 I=0 N=4 O=6 T=8 V=2 W=7
    (671 + 826 + 9041 = 10538) / E=1 F=9 G=5 H=3 I=0 N=7 O=6 T=8 V=4 W=2
    (671 + 846 + 9021 = 10538) / E=1 F=9 G=5 H=3 I=0 N=7 O=6 T=8 V=2 W=4
    

    But we can use it in a program and add code to group the solutions.

    This Python program runs in 240ms.

    Run: [ @repl.it ]

    from collections import Counter
    from enigma import SubstitutedSum, printf
    
    # make the alphametic sum
    p = SubstitutedSum(["ONE", "TWO", "FIVE"], "EIGHT")
    
    # collect the solutions
    r = Counter(p.substitute(s, p.result) for s in p.solve(verbose=1))
    
    # output solutions
    for (k, v) in r.most_common():
      printf("{p.result} = {k} [{v} solutions]")
    
  2. GeoffR 3 May 2019 at 12:22 pm
    % A solution in MinZinc 
    include "globals.mzn";
    
    var 1..9: O; var 0..9: N; var 1..9: E; var 1..9: T; var 0..9: W;
    var 1..9: F; var 0..9: I; var 0..9: V; var 0..9: G; var 0..9: H;
    
    constraint all_different([O, N, E, T, W, F, I, V, G, H]);
    
    var 100..999: ONE = 100*O + 10*N + E;
    var 100..999: TWO = 100*T + 10*W + O;
    var 1000..9999: FIVE = 1000*F + 100*I + 10*V + E;
    var 10000..99999: EIGHT = 10000*E + 1000*I + 100*G + 10*H + T;
    
    constraint ONE + TWO + FIVE == EIGHT;
    solve satisfy;
    
    output [ show(ONE) ++ " + " ++ show(TWO) ++ " + " ++
    show(FIVE) ++ " = " ++ show(EIGHT) ];
    
    % 671 + 846 + 9021 = 10538
    % 641 + 876 + 9021 = 10538
    % 671 + 826 + 9041 = 10538
    % 621 + 876 + 9041 = 10538
    % 641 + 826 + 9071 = 10538
    % 621 + 846 + 9071 = 10538
    % ----------
    % ==========
    % Finished in 235msec
    
    

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

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

%d bloggers like this: