Enigmatic Code

Programming Enigma Puzzles

Enigma 1347: Fair and square

From New Scientist #2506, 2nd July 2005

If you let A=1, B=2, C=3 etc then you can use these values to calculate the total score of any word. For example, ENIGMA has a score of 49. Interestingly SQUARE has a score which is square, PRIME has a score which is prime, ODD has a score which is odd, and EVEN has a score which is even.

I have now adjusted the values of some of the letters. For twenty-three letters their value is the same as before, but for the remaining three their values have been shuffled around. (For example I could have shuffled B, E and H to give B=8, E=2, H=5 with the other letters unchanged.) With these new values SQUARE has a different score from before but it is still square, PRIME has a lower score than before but it is still prime, ODD is still odd and EVEN is still even (but at least one of these last two words has a different score from before).

Which three letters have had their values changed, and what are their new values?



3 responses to “Enigma 1347: Fair and square

  1. Jim Randell 13 February 2014 at 8:28 am

    This Python program runs in 55ms.

    from itertools import combinations
    from enigma import irange, is_square, is_prime, printf
    # find the value of a word
    def value(word, d):
      return sum(d[x] for x in word)
    # letters
    # initial dictionary
    d = dict((x, i + 1) for (i, x) in enumerate(letters))
    # initial values
    (ENIGMA, SQUARE, PRIME, ODD, EVEN) = (value(x, d) for x in ('ENIGMA', 'SQUARE', 'PRIME', 'ODD', 'EVEN'))
    assert ENIGMA == 49 and is_square(SQUARE) and is_prime(PRIME) and ODD % 2 == 1 and EVEN % 2 == 0
    # choose three letters
    for s in combinations(letters, 3):
      ss = set(s)
      # they need to include at least one letter from both SQUARE and PRIME
      if not(ss.intersection('SQUARE') and ss.intersection('PRIME')): continue
      # and at least one letter of either ODD or EVEN
      if not(ss.intersection('ODD')) and not(ss.intersection('EVEN')): continue
      # now shuffle the dictionary
      for js in ((1, 2, 0), (2, 0, 1)):
        d2 = dict(d)
        for (x, j) in zip(s, js):
          d2[x] = d[s[j]]
        # SQUARE is a different square
        SQUARE2 = value('SQUARE', d2)
        if not(SQUARE2 != SQUARE and is_square(SQUARE2)): continue
        # PRIME is a lower prime
        PRIME2 = value('PRIME', d2)
        if not(PRIME2 < PRIME and is_prime(PRIME2)): continue
        # ODD is odd
        ODD2 = value('ODD', d2)
        if not(ODD2 % 2 == 1): continue
        # EVEN is even
        EVEN2 = value('EVEN', d2)
        if not(EVEN2 % 2 == 0): continue
        # and at least one of them must be different
        if ODD2 == ODD and EVEN2 == EVEN: continue
        # print the new values of the changed letters
        r = ' '.join(x + '=' + str(d2[x]) for x in s)
        printf("{r} [SQUARE: {SQUARE}->{SQUARE2}, PRIME: {PRIME}->{PRIME2}, ODD: {ODD}->{ODD2}, EVEN: {EVEN}->{EVEN2}]")

    Solution: The three changed letters are: D=21, R=4, U=18.

  2. jwillmington 15 July 2016 at 2:14 pm

    I’m getting an additional answer:-
    D = 9, I=21, U=4 giving 64, 73, 46 and 33 for square, prime, even and odd
    Perhaps this is excluded because Enigma is changed but the setter does not seem to specify that it must remain unchanged.

    • Jim Randell 17 July 2016 at 10:41 pm

      The value of PRIME needs to be smaller using the new values than it was using the old values.

      With the old values PRIME has a score of 61, but using the new values you give you get a score of 73. This is prime, but it cannot give a solution as it is larger than the original value.

      There are two solutions where the new value of PRIME is larger than the old value: D=9, I=21, U=4 and E=17, Q=24, X=5.

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

%d bloggers like this: