Enigmatic Code

Programming Enigma Puzzles

Enigma 1664: Summer sextet

From New Scientist #2830, 17th September 2011 [link]

My nephew Ignatius has set me a problem. He has written down the digits 0 to 9 in ascending order, and has struck out zero and three other digits. He assigned the remaining six, in ascending order, to the letters P, A, Y, E, R and S, respectively. He then produced the sum shown, translated from six three-digit numbers, and their total.

To what number does PAYERS correspond?

[enigma1664]

2 responses to “Enigma 1664: Summer sextet

  1. Jim Randell 4 December 2011 at 12:12 am

    A little observation makes this a very short program.

    The following Python code runs in 30ms

    # NOTE: each column sums P+A+Y+E+R+S, so the sum is 111*(P+A+Y+E+R+S)
    
    from itertools import combinations
    from enigma import irange, concat
    
    # s = (P, A, Y, E, R, S)
    for s in combinations(irange(1, 9), 6):
      if 111 * sum(s) == int(concat(s[2], s[1], s[0], s[5])):
        print(concat(*s))
    

    Solution: PAYERS = 123689.

  2. geoffrounce 31 May 2018 at 4:14 pm
    % A Solution in MiniZinc
    include "globals.mzn";
    
    var 1..9:P;  var 1..9:A;  var 1..9:Y;  
    var 1..9:E;  var 1..9:R;  var 1..9:S;  
    
    var 100..999: PAY = 100*P + 10*A + Y;
    var 100..999: ASP = 100*A + 10*S + P;
    var 100..999: YES = 100*Y + 10*E + S;
    var 100..999: ERR = 100*E + 10*R + R;
    var 100..999: RYE = 100*R + 10*Y + E;
    var 100..999: SPA = 100*S + 10*P + A;
    
    var 1000..9999: YAPS = 1000*Y + 100*A + 10*P + S;
    var 100000..999999: PAYERS = 100000*P + 10000*A + 1000*Y + 100*E + 10*R + S;
    
    constraint all_different( [P, A, Y, E, R, S] )
    /\ P < A /\ A < Y /\ Y < E /\ E < R /\ R < S;
    
    constraint PAY + ASP + YES + ERR + RYE + SPA = YAPS;
    
    solve satisfy;
    
    output [ "PAYERS = " ++ show(PAYERS) ];
    
    % PAYERS = 123689
    
    

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: