Enigmatic Code

Programming Enigma Puzzles

Enigma 73: Quartetting

From New Scientist #1216, 28th August 1980 [link]

Enigma 73The quartet-numbers in the circles show the sums of the numbers in the four surrounding squares. The object is to arrange the numbers 1 to 9 in the squares so that the quartet-numbers, ignoring the two biggest ones, are as small as possible. The arrangement shown achieves a maximum quartet-number of 14, ignoring the two 26’s.

I ask you to arrange the numbers 1 to 16 in a 4 × 4 grid, so that the greatest of the nine quartet-numbers (ignoring the two biggest) is as small as possible. What is the least third-greatest quartet-number you can achieve? (The best pattern, I may add, is not unique).

This is somewhat similar to the Sujiko puzzles published in the Daily Telegraph, although those seem to have been “invented” in 2010, so this Enigma predates that by some 30 years.

[enigma73]

Advertisements

3 responses to “Enigma 73: Quartetting

  1. Jim Randell 20 March 2013 at 10:01 am

    This program examines all possible quartet values and comes up with the solution in 1m36s (using PyPy), so it’s not particularly quick, or particularly elegant.

    from bisect import insort
    from itertools import combinations, product
    from enigma import irange, printf
    
    def insert(a, x):
      b = list(a)
      insort(b, x)
      return b
    
    ns0 = set(irange(1, 16))
    m = sum(ns0)
    
    # to reduce duplicates lets assume q1 <= q3 <= q7, q1 <= q9
    for q1s in combinations(ns0, 4):
      q1 = sum(q1s)
      ns1 = ns0.difference(q1s)
      for q3s in combinations(ns1, 4):
        q3 = sum(q3s)
        if q3 < q1: continue
        ns2 = ns1.difference(q3s)
        for q7s in combinations(ns2, 4):
          q7 = sum(q7s)
          if q7 < q3: continue
          q9s = ns2.difference(q7s)
          q9 = sum(q9s)
          if q9 < q1: continue
          s1 = sorted((q1, q3, q7, q9))
          if not(s1[-3] < m): continue
    
          for (q12s, q23s) in product(combinations(q1s, 2), combinations(q3s, 2)):
            q2s = q12s + q23s
            q2 = sum(q2s)
            s2 = insert(s1, q2)
            if not(s2[-3] < m): continue
    
            for (q78s, q89s) in product(combinations(q7s, 2), combinations(q9s, 2)):
              q8s = q78s + q89s
              q8 = sum(q8s)
              s3 = insert(s2, q8)
              if not(s3[-3] < m): continue
    
              for q5s in product(q12s, q23s, q78s, q89s):
                q5 = sum(q5s)
                s4 = insert(s3, q5)
                if not(s4[-3] < m): continue
    
                (q1s, q7s) = (set(q1s), set(q7s))
                for a in product(q1s.difference(q12s), q7s.difference(q78s)):
                  q4s = set(a).union(q1s.intersection(q5s), q7s.intersection(q5s))
                  q4 = sum(q4s)
                  s5 = insert(s4, q4)
                  if not(s5[-3] < m): continue
    
                  (q3s, q9s) = (set(q3s), set(q9s))
                  for b in product(q3s.difference(q23s), q9s.difference(q89s)):
                    q6s = set(b).union(q3s.intersection(q5s), q9s.intersection(q5s))
                    q6 = sum(q6s)
                    s6 = insert(s5, q6)
                    v = s6[-3]
                    if v < m: m = v
    
    printf("min value = {m}")
    

    Solution: The minimal third-greatest quartet number is 24.

    I augmented the code to count the number of solutions and it found 192.

    One way to achieve the solution is shown below:

    Enigma 73 Solution

  2. Naim Uygun 31 March 2013 at 6:15 pm

    Where are the attorneys of the New Scientist Magazine?
    Why don’t they interfere with those fake inventors?

  3. Jai Kobayaashi Gomer 3 March 2014 at 9:21 am

    Jim : I’d like to thank you for bringing this example of the grid and node playboard to light. I’ve not come across this before, and it shows that, as the saying goes, “there is nothing new under the sun”.

    I would like to point out, however, that though the playboard is the same as that used for Sujiko, the puzzle itself differs greatly, as does the method of play, and far from being a “fake inventor”, I believe that I created a puzzle which not only differs from this example, but also from all others which were in circulation in 2010.

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: