Enigmatic Code

Programming Enigma Puzzles

Enigma 1707: Making progress

From New Scientist #2874, 21st July 2012 [link]

I was teaching my nephew about arithmetic progressions – sequences like 17, 23, 29,… 677,… in which the common difference between successive terms is a constant. In this one the difference is 6 and the 111th term is 677. Later, he devised his own progression, but consistently replaced digits with capital letters, with different letters for different digits. His sequence was ONE, TWO,… THREE,… with the 111th term being THREE. The common difference was odd and more than the number represented by SIX.

Tell me the number represented by SENT?

[enigma1707]

7 responses to “Enigma 1707: Making progress

  1. Jim Randell 18 July 2012 at 5:26 pm

    The following Python program runs in 160ms.

    from itertools import permutations
    from enigma import irange, concat, split, printf
    
    # the nth term in an arithmetic progression is: a[n] = a[1] + (n - 1) d
    
    ds = set(irange(0, 9))
    for (O, N, E) in permutations(ds, 3):
      if O == 0: continue
      ONE = int(concat(O, N, E))
    
      ds2 = ds.difference((O, N, E))
      for (T, W) in permutations(ds2, 2):
        if T == 0: continue
        TWO = int(concat(T, W, O))
        d = TWO - ONE
        if d < 0 or d % 2 == 0: continue
    
        THREE = str(ONE + 110 * d)
        if len(THREE) != 5: continue
    
        (t, H, R, e1, e2) = split(THREE, int)
        if not(t == T and e1 == e2 == E): continue
    
        ds3 = ds2.difference((T, W, H, R))
        if len(ds3) != 3: continue
    
        for (S, I, X) in permutations(ds3, 3):
          if S == 0: continue
          SIX = int(concat(S, I, X))
          if not(SIX < d): continue
    
          SENT = concat(S, E, N, T)
    
          printf("SENT={SENT} [d={d} ONE={ONE} TWO={TWO} THREE={THREE} SIX={SIX}]")
    

    Solution: SENT = 4236.

  2. Geoff Rounce 18 July 2012 at 6:29 pm

    My solution gives a unique answer, I think:

       
    from itertools import permutations
    
    for p in permutations('1234567890', 10):
        ndict = dict(zip('ONETWHRSIX', p))
        if p[0] != '0':
            one = int(''.join(ndict[x] for x in 'ONE'))
        if p[3] != '0':
            two = int(''.join(ndict[x] for x in 'TWO'))
        if p[6] != '0':
            three = int(''.join(ndict[x] for x in 'THREE'))
        six = int(''.join(ndict[x] for x in 'SIX'))
        sent = int(''.join(ndict[x] for x in 'SENT'))
        # teaser conditions
        if (one + (two-one)*110 == three) and (two-one)%2 == 1 and (two-one)>six:
            print('one,two,diff,six,three,sent = ',one,two,(two-one),six,three,sent)
            break
     

    – after code

  3. Paul Coyle 25 March 2020 at 3:22 pm

    Sorry to be late to the party. I do these in excel with vb so often not as pretty or succinct as python.
    I found lots of solutions {where 0 is o) and another 4 when o was 1. It’s ugly code

    • Jim Randell 25 March 2020 at 5:10 pm

      @Paul: It’s normal in this type of puzzle to assume that numbers with leading zeros are not permitted. So in this example O, T, S would not be allowed to be zero. (I check this in my program at lines 8, 13, 28).

      Assuming these restrictions you should be able to find the required solution (there are two possible values for SIX, but only one for ONE, TWO, THREE, SENT).

  4. Jim Randell 26 March 2020 at 7:43 am

    Here is a solution using the [[ SubstitutedExpression() ]] solver from the enigma.py library. It executes in 176ms.

    Run: [ @repl.it ]

    #!/usr/bin/env python -m enigma -r
    
    SubstitutedExpression
    
    # the common difference d = TWO - ONE
    
    # 111th term is THREE
    "ONE + 110 * (TWO - ONE) = THREE"
    
    # common difference is odd
    "(TWO - ONE) % 2 = 1"
    
    # common difference is greater than SIX
    "TWO - ONE > SIX"
    
    # required answer
    --answer="SENT"
    
  5. GeoffR 26 March 2020 at 9:58 am
    % A Solution in MiniZinc
    include "globals.mzn";
    
    var 0..9:E; var 0..9:H; var 0..9:I; var 0..9:N;
    var 0..9:O; var 0..9:R; var 1..9:S; var 1..9:T;
    var 0..9:W; var 0..9:X;
    
    constraint all_different([E,H,I,N,O,R,S,T,W,X]);
    
    var 100..999: ONE = 100*O + 10*N + E;
    var 100..999: TWO = 100*T + 10*W + O;
    var 10000..99999: THREE = 10000*T + 1000*H + 100*R + 11*E;
    var 100..999: SIX = 100*S + 10*I + X;
    var 1000..9999: SENT = 1000*S + 100*E + 10*N + T;
    
    % The 111th term is THREE and the common difference is odd
    constraint ONE + 110 * (TWO - ONE) == THREE
    /\ (TWO - ONE) mod 2 == 1 /\ TWO - ONE > SIX;
    
    solve satisfy;
    
    output ["SENT = " ++ show(SENT) ];
    % SENT = 4236
    % ----------
    % ==========
    
    
    

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: