Enigmatic Code

Programming Enigma Puzzles

Enigma 241: The other magic cuboctahedron

From New Scientist #1387, 8th December 1983 [link]

Enigma 241

The picture shows a cuboctahedron, with 12 vertices lettered A to L, and 14 faces, of which six are squares and eight are triangles.

The problem is to place a different positive whole number so that the sum of the numbers at the corners of each square face is the same and the sum of the numbers at the corners of each triangular face is the same.

In doing so, first make the number at A as small as possible. Then make B as small as possible. Then C … and so on.

What numbers go at IJKL?

[enigma241]

Advertisements

One response to “Enigma 241: The other magic cuboctahedron

  1. Jim Randell 29 November 2014 at 8:03 am

    Enigma 225 was about labelling the faces on a cuboctahedron.

    This Python 3 program finds the best solution in 326ms.

    from itertools import count
    from enigma import irange, filter2, diff, printf
    
    # label the vertices from 0 to 11 and consider the vertices around each face
    groups = (
      # squares
      (0, 1, 2, 3), # ABCD
      (0, 4, 5, 8), # AEFI
      (1, 4, 6, 9), # BEGJ
      (2, 5, 7, 10), # CFHK
      (3, 6, 7, 11), # DGHL
      (8, 9, 10, 11), # IJKL
      # triangles
      (0, 1, 4), # ABE
      (0, 2, 5), # ACF
      (1, 3, 6), # BDG
      (2, 3, 7), # CDH
      (4, 8, 9), # EIJ
      (5, 8, 10), # FIK
      (6, 9, 11), # GJL
      (7, 10, 11), # HKL
    )
    
    def update(d, k, v):
      d = d.copy()
      d[k] = v
      return d
    
    # m - map of vertex to number
    # vs - remaining vertices (in order)
    # ns - allocated numbers
    # gs - remaining groups
    # ss - common sum (indexed by number of elements in group)
    def solve(m, vs, ns, gs, ss):
      # are we done?
      if not gs:
        yield m
      else:
        # examine the remaining groups
        for i in gs:
          # common sum for this group
          s = ss[len(groups[i])]      
          # count assigned and unassigned vertices in this group
          (va, vu) = filter2(lambda v: v in m, groups[i])
          if len(vu) == 0:
            # all vertices assigned
            g = sum(m[v] for v in va)
            # does it match the common sum?
            if g == s:
              yield from solve(m, vs, ns, diff(gs, [i]), ss)
            return
    
          elif len(vu) == 1:
            # there's 1 vertex remaining, what number should it be labelled with?
            n = s - sum(m[v] for v in va)
            if n < 1 or n in ns: return
            v = vu[0]
            yield from solve(update(m, v, n), diff(vs, [v]), ns + [n], diff(gs, [i]), ss)
            return
    
        else:
          # label the lowest vertex
          v = vs[0]
          for n in irange(1, max(ss.values())):
            if n in ns: continue
            yield from solve(update(m, v, n), vs[1:], ns + [n], gs, ss)
    
    # if S is the common sum of the square faces, and T is the common sum
    # of the triangular faces and V is the sum of all vertices we get:
    #   V = A + B + C + D + E + F + G + H + I + J + K + L
    #   6S = 2V
    #   8T = 2V
    # hence:
    #   3S = 4T = V
    # so T must be divisible by 3 (and must be at least 10)
    
    def main():
      for x in count(4):
        for m in solve({}, list(irange(0, 11)), [], tuple(i for (i, _) in enumerate(groups)), { 4: 4 * x, 3: 3 * x }):
          printf("{m} [S={S} T={T}]", m=' '.join(x + '=' + str(m[i]) for (i, x) in enumerate('ABCDEFGHIJKL')), S=4 * x, T=3 * x)
          return
    
    main()
    

    Solution: I = 4; J = 5; K = 6; L = 13.

    The complete layout is as follows:

    A = 1; B = 8; C = 9; D = 10; E = 12; F = 11; G = 3; H = 2; I = 4; J = 5; K = 6; L = 13;

    Enigma 241 - Solution

    The numbers on the red background label the vertices. The black numbers on the faces indicate the sum of the surrounding vertices.

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: