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?



3 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)

    – after code

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: