Enigmatic Code

Programming Enigma Puzzles

Enigma 1407: Fun in the sun

From New Scientist #2567, 2nd September 2006

I have just returned from my summer holidays and am now in a position to confirm what the holiday brochures say – Ibiza is made up of sand, sun, sex and sea! In fact you can see this by setting out the addition sum (below) in which each letter consistently replaces a different digit and the numbers being added are in decreasing order.

Enigma 1407

What is the value of IBIZA?

[enigma1407]

Advertisements

7 responses to “Enigma 1407: Fun in the sun

  1. Jim Randell 30 July 2013 at 9:32 am

    This Python program uses the SubstitutedSum() solver from the enigma.py library (originally written for Enigma 63). It runs in 350ms.

    from enigma import SubstitutedSum, printf
    
    p = SubstitutedSum(['SAND', 'SUN', 'SEX', 'SEA'], 'IBIZA')
    for s in p.solve():
      # what are the summands as integers?
      ns = list(int(p.substitute(s, n)) for n in p.terms)
      if ns == sorted(ns, reverse=True):
        printf("IBIZA={i} [{t}]", i=p.substitute(s, p.result), t=p.substitute(s, p.text))
    

    Solution: IBIZA = 12183.

    There are two ways of arriving at the solution as the values for the letters D and X are interchangeable.

  2. Naim Uygun 30 July 2013 at 10:48 am

    Only using the site http://www.iread.it and Excel
    SAND+SUN+SEX+SEA=IBIZA
    9306+970+954+953=12183
    OR
    9304+970+956+953=12183

  3. geoffrounce 30 July 2013 at 10:56 am

    A standard permutation solution:

    from itertools import permutations
    for p in permutations((1,2,3,4,5,6,7,8,9,0)):
        s,a,n,d,u,e,x,i,b,z = p
        if s != 0 and i!=0:
            sand = d + n*10 + a*100 + s*1000
            sun = n + u*10 + s*100
            sex = x + e*10 + s*100
            sea = a + e*10 + s*100
            ibiza = a + z*10 + i*100 + b*1000 + i*10000
            if sea < sex and sex < sun and sun < sand:
                if sand + sun + sex + sea == ibiza:
                    print("Ibiza = ", ibiza)
    
    • Jim Randell 30 July 2013 at 11:12 am

      If you’re interested in a little Python tip you could write the ordering inequality as:

      if sea < sex < sun < sand:
        ...
      

      It looks neater, and it may be a tiny bit more efficient.

      • geoffrounce 19 August 2016 at 7:49 pm

        The ordering inequality suggested looks good for Python, but did not work for me in MiniZinc
        Without the ordering inequality, IBIZA can be 10128, 10148, 10168, 10189 or 12183.

        % A Solution in MiniZinc
        include "globals.mzn";
        
        var 0..9:S;  var 0..9:A;  var 0..9:N;  var 0..9:D;  var 0..9:U; 
        var 0..9:E;  var 0..9:X;  var 0..9:I;  var 0..9:B;  var 0..9:Z;
        
        constraint alldifferent([S,A,N,D,U,E,X,I,B,Z])
        /\ S > 0 /\ I > 0;
        
        var 1000..9999: SAND = 1000*S + 100*A + 10*N + D;
        var 100..999: SUN = 100*S + 10*U + N;
        var 100..999: SEX = 100*S + 10*E + X; 
        var 100..999: SEA = 100*S + 10*E + A; 
        var 10000..99999: IBIZA = 10000*I + 1000*B + 100*I + 10*Z + A;
        
        constraint SAND + SUN + SEX + SEA == IBIZA
        /\ SEA < SEX /\ SEX < SUN /\ SUN < SAND;
        
        solve satisfy;
        
        output["IBIZA = " ++ show(I),show(B),show(I),show(Z),show(A)];
        % IBIZA = 12183
        % Finished in 83msec
        %
        
  4. Pingback: Enigma 1407: SAND + SUN + SEA + SEX = IBIZA | Ben's Blogs, Books & Pix

  5. Jim Randell 19 August 2016 at 11:26 pm

    This puzzle was also one of the examples I used when writing the generalised Alphametic solver in the enigma.py library (SubstitutedExpression()). See the articles Solving Alphametics with Python and Solving Alphametics with Python, Part 2 for more details.

    Using the command-line invocation we can solve the problem in 391ms. Here is the command and its output:

    % pypy -m enigma SubstitutedExpression \
        --answer="IBIZA" \
        "SAND + SUN + SEX + SEA = IBIZA" \
        "SAND > SUN > SEX > SEA"
    (SAND + SUN + SEX + SEA = IBIZA) (SAND > SUN > SEX > SEA)
    (9304 + 970 + 956 + 953 = 12183) (9304 > 970 > 956 > 953) / A=3 B=2 D=4 E=5 I=1 N=0 S=9 U=7 X=6 Z=8 / 12183
    (9306 + 970 + 954 + 953 = 12183) (9306 > 970 > 954 > 953) / A=3 B=2 D=6 E=5 I=1 N=0 S=9 U=7 X=4 Z=8 / 12183
    IBIZA = 12183 [2 solutions]
    

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: