Enigmatic Code

Programming Enigma Puzzles

Enigma 1598: Twin squares

From New Scientist #2763, 5th June 2010 [link]

For my birthday, my wife Astrid made identical sets of cards. On each card a letter of ASTRIDOWEN is displayed, together with its own characteristic digit chosen from 0-9. On the day, Astrid’s sister Enid sat on our three-seater settee with our twins Eden and Toni and, when they held up the cards with their respective names, the numbers on the cards satisfied:

ENID2 = EDENTONI (read off as an eight-digit number).

When my brother Ewan arrived, we found that:

EWAN2 = TONIEDEN.

The twins then made up a set of cards for their “taid” (Welsh grandfather).

What eight-digit number corresponds to TAIDOWEN?

[enigma1598]

Advertisements

3 responses to “Enigma 1598: Twin squares

  1. jimrandell 11 January 2012 at 2:27 pm

    The following Python program runs in 72ms.

    You only need to consider the possibilities for E, N, I, D — the other letters are implied.

    from itertools import permutations
    from enigma import concat, split, is_square, printf
    
    # find possibilities for ENID
    for (E, N, I, D) in permutations(range(10), 4):
      if E == 0: continue
      ENID = int(concat(E, N, I, D))
    
      # check ENID^2 = EDENTONI
      ENID2 = str(ENID * ENID)
      if len(ENID2) != 8: continue
      (E1, D1, E2, N1, T, O, N2, I1) = split(ENID2, int)
      if T == 0: continue
      if not(E == E1 == E2 and D == D1 and N == N1 == N2 and I == I1): continue
      d = set((E, N, I, D, T, O))
      if len(d) != 6: continue
    
      # check EWAN^2 = TONIEDEN
      TONIEDEN = int(concat(T, O, N, I, E, D, E, N))
      EWAN = is_square(TONIEDEN)
      if not EWAN: continue
      (E1, W, A, N1) = split(EWAN, int)
      if not(E == E1 and N == N1): continue
    
      TAIDOWEN = concat(T, A, I, D, O, W, E, N)
    
      printf("TAIDOWEN={TAIDOWEN} [ENID={ENID} EDENTONI={ENID2} TONIEDEN={TONIEDEN} EWAN={EWAN}]")
    

    Solution: TAIDOWEN = 83421096.

    • Jim Randell 9 September 2016 at 8:40 am

      Here’s a solution using the general Alphametic solver (SubstitutedExpression()) from the enigma.py library. Overall run-time is 73ms.

      % python -m enigma SubstitutedExpression \
          --answer="TAIDOWEN" \
          "ENID ** 2 = EDENTONI" \
          "EWAN ** 2 = TONIEDEN"
      (ENID ** 2 = EDENTONI) (EWAN ** 2 = TONIEDEN)
      (9642 ** 2 = 92968164) (9036 ** 2 = 81649296) / A=3 D=2 E=9 I=4 N=6 O=1 T=8 W=0 / 83421096
      TAIDOWEN = 83421096 [1 solution]
      
  2. geoffrounce 8 September 2016 at 8:07 pm
    % A solution in MiniZinc
    include "globals.mzn";
    
    var 0..9: A;  
    var 0..9: T; 
    var 0..9: I; 
    var 0..9: D;
    var 0..9: O; 
    var 0..9: W; 
    var 0..9: E; 
    var 0..9: N;
    
    array[1..8] of var int : dig = [A,T,I,D,O,W,E,N];
    constraint all_different(dig) /\ E > 0 /\ T > 0;
    
    var 1000..9999: ENID = E*1000 + 100*N + I*10 + D;
    var 1000..9999: EWAN = E*1000 + W*100 + A*10 + N;
    
    var 10000000..99999999: TAIDOWEN = 10000000*T + 1000000*A +
    100000*I + 10000*D + 1000*O + 100*W + 10*E + N;
    
    var 10000000..99999999: EDENTONI = 10000000*E + 1000000*D + 
    E*100000 + N*10000 + T*1000 + O*100 + N*10 + I;
    
    var 10000000..99999999: TONIEDEN = 10000000*T + 1000000*O +
    100000*N + 10000*I + 1000*E + 100*D + 10*E + N;
    
    constraint ENID * ENID == EDENTONI /\ EWAN * EWAN == TONIEDEN;
    solve satisfy;
    
    output["TAIDOWEN = " ++ show(TAIDOWEN)];
    
    % TAIDOWEN = 83421096
    % Finished in 83msec
    

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: