Enigmatic Code

Programming Enigma Puzzles

Enigma 1297: In order to be true

From New Scientist #2455, 10th July 2004

We write “b + n = f + l + 1” to stand for the sentence, “the number of b’s plus the number of n’s equals the number of f’s plus the number of l’s plus one.”

In a similar way, write each of the following as a sentence in words;

m + t = p + r + 2;
a + e = h + r + 3;
f + r = h + l + 4;
l + n = f + p + 5;
t + u = a + e + 6.

Your problem is to put the six sentences you have (including the first example) into a certain order so that you have a paragraph of text with the following property:

If you take the text from the start of the paragraph up to the end of any particular sentence and count the letters in that text then you will find that particular sentence is a true statement about the text.

List the final words of the six sentences in the order in which they occur in the paragraph.

Note: I am waiting for a phone line to be connected at my new house, so I only have sporadic access to the internet at the moment.



One response to “Enigma 1297: In order to be true

  1. Jim Randell 2 September 2014 at 11:05 am

    This Python program solves the puzzle recursively in 38ms.

    # the (parameterised) sentence
    fmt = "the number of {}'s plus the number of {}'s equals the number of {}'s plus the number of {}'s plus {}.\n"
    # the sentence parameters
    ss = (
      ('bnfl', 1),
      ('mtpr', 2),
      ('aehr', 3),
      ('frhl', 4),
      ('lnfp', 5),
      ('tuae', 6),
    # delete an element from a list
    def delete(ss, i):
      ss = list(ss)
      del ss[i]
      return ss
    # ss - remaining sentence parameters
    # text - current accumulated text
    # s - sequence of sentences
    def solve(ss, text='', s=[]):
      # are we done?
      if not ss:
        printf("text = >>>\n{text}<<<\n")
        printf("solution = {s}\n", s=', '.join(s))
        # consider each sentence
        for (i, (cs, n)) in enumerate(ss):
          # extend the text with this sentence
          w = int2words(n)
          t = text + fmt.format(*(tuple(cs) + (w,)))
          # count the 4 parameterised characters 
          (n1, n2, n3, n4) = (t.count(c) for c in cs)
          # check the sum
          if n1 + n2 == n3 + n4 + n:
            # solve the remaining sentences
            solve(delete(ss, i), t, s + [w])

    Solution: The final six words of the sentences in the paragraph are: two, three, one, six, five, four.

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: