Enigmatic Code

Programming Enigma Puzzles

Enigma 1330: Rain puzzle

From New Scientist #2489, 5th March 2005

I had just completed a new puzzle when it began to rain. Unfortunately raindrops fell on seven letters in the manuscript, turning them into illegible blobs. In the copy of the puzzle that follows, those seven blobs are marked by stars.

Puzzle: I have a 4-by-4 array of 16 squares, and each square contains a letter. I will tell you the letters in each horizontal row and each vertical column in alphabetical order. The rows are numbered from top to bottom and the columns from left to right.

Row 1, abcd; Row 2, cefg; Row 3, adeh; Row 4 bfgh.

Column 1, adeg; Column 2, bcfh; Column 3, a***; Column 4, ****.

From this information you will find precisely two possible answers. I want you to look at the letter in Row 2, Column 3 in each answer and send in the 4-by-4 array for which that letter is the earliest in the alphabet.

What was the answer to the puzzle?



One response to “Enigma 1330: Rain puzzle

  1. Jim Randell 22 April 2014 at 8:11 am

    This Python program runs in 227ms.

    from collections import defaultdict
    from itertools import permutations
    r = defaultdict(list)
    for r1 in permutations('abcd'):
      for r2 in permutations('cefg'):
        for r3 in permutations('adeh'):
          for r4 in permutations('bfgh'):
            c1 = (r1[0], r2[0], r3[0], r4[0])
            if sorted(c1) != ['a', 'd', 'e', 'g']: continue
            c2 = (r1[1], r2[1], r3[1], r4[1])
            if sorted(c2) != ['b', 'c', 'f', 'h']: continue
            c3 = (r1[2], r2[2], r3[2], r4[2])
            if 'a' not in c3: continue
            c4 = (r1[3], r2[3], r3[3], r4[3])
            # record solutions by the missing 7 letters
            r[tuple(sorted(c3)[1:] + sorted(c4))].append((r1, r2, r3, r4))
    # we need find find cases where there are two possible solutions
    for (k, v) in r.items():
      if len(v) != 2: continue
      # and the entries in r2c3 must be different
      r2c3 = lambda x: x[1][2]
      if r2c3(v[0]) == r2c3(v[1]): continue
      # find the one with the lowest value
      m = min(v, key=r2c3)
      print('\n'.join(' '.join(x) for x in m) + '\n')

    Solution: The answer to the puzzle is the following grid:

    Enigma 1330 - Solution

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: