Enigmatic Code

Programming Enigma Puzzles

Enigma 225: Magic cuboctahedron

From New Scientist #1371, 18th August 1983 [link]

The picture shows a cuboctahedron, A semi-regular solid with six square faces and eight triangular ones. It has 12 vertices, lettered from A to L.

Enigma 225

Can you place the numbers 1 to 14, one on each face, so that the numbers round each vertex add up to the same “magic sum”?

That magic sum should be made as small as possible, please.

Please let me know:

(A) What the magic sum is.
(B) What numbers are on the faces having an edge in common with the 7-face.

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. The current estimate is that the line will be connected at the end of September 2014.

[enigma225]

Advertisements

One response to “Enigma 225: Magic cuboctahedron

  1. Jim Randell 26 September 2014 at 1:35 pm

    This Python 3 program runs in 392ms.

    from enigma import irange, diff, filter2, printf
    
    # label the faces 0 to 13 and consider the faces around each vertex
    groups = (
      (0, 1, 2, 3), # A
      (2, 3, 4, 5), # B
      (3, 5, 6, 7), # C
      (0, 3, 7, 8), # D
      (1, 2, 4, 9), # E
      (4, 5, 6, 10), # F
      (6, 7, 8, 11), # G
      (0, 1, 8, 12), # H
      (1, 9, 12, 13), # I
      (4, 9, 10, 13), # J
      (6, 10, 11, 13), # K
      (8, 11, 12, 13), # L
    )
    
    # decompose total <t> into <n> numbers from <ns>
    def decompose(t, ns, n):
      if n == 1:
        if t in ns:
          yield [t]
      else:
        for x in ns:
          if x > t: break
          for y in decompose(t - x, diff(ns, [x]), n - 1):
            yield [x] + y
    
    # update dictionary <d> with (key,values) from <v>
    def update(d, v):
      d = d.copy()
      d.update(v)
      return d
    
    
    # fill out the numbers
    # s - magic sum
    # m - map of face to number
    # ns - remaining numbers
    # gs - remaining groups (by index)
    def solve(s, m, ns, gs):
      # are we done?
      if not ns:
        yield m
      else:
        # choose the group with the least remaining faces
        (i, (rs, fs)) = min(((i, filter2(lambda f: f not in m, groups[i])) for i in gs), key=lambda x: x[1][0])
        # sum of the allocated faces
        t = sum(m[f] for f in fs)
        # choose the remaining numbers for that face
        for ds in decompose(s - t, ns, len(rs)):
          # assign the faces and solve
          yield from solve(s, update(m, zip(rs, ds)), diff(ns, ds), diff(gs, [i]))
    
    def main():
      # there are 6 square faces and 8 triangular faces, and 12 vertices
      # so if the magic sum is s:
      #  3(1 + ... + 14) + (1 + ... + 6) <= 12s <= 3(1 + ... + 14) + (9 + ... + 14)
      #  28 <= s <= 32
      for s in irange(28, 32):
        # remaining numbers and groups
        ns = diff(irange(1, 14), [7])
        gs = tuple(i for (i, _) in enumerate(groups))
        # try with 7 on a triangular face (0) and a square face (1)
        for (f, adj) in ((0, (1, 3, 8)), (1, (0, 2, 9, 12))):
          n = 0
          for r in solve(s, {f: 7}, ns, gs):
            printf("s={s} {r}, adj(7) = {a}", a=tuple(r[i] for i in adj))
            n += 1
          # stop at the first s with solutions
          if n > 0: return
    
    main()
    

    Solution: (A) The magic sum is 28. (B) The faces with 3, 5 and 6 on share an edge with the face with 7 on.

    Here’s a diagram of the solution:

    Enigma 225 - Solution

    (The cuboctahedron is “punctured” in the middle of the face IJKL, and the hole is then stretched out to make the perimeter of a flat disc).

    There are multiple solutions where the magic sum is 30. In this case the 7 face can be surrounded by (1, 9, 10), (2, 10, 12), (4, 6, 14), (4, 5, 6) or (9, 10, 12) if it is on a triangular face, or (1, 9, 10, 11) if it is on a square face.

    There is also a solution where the magic sum is 32. In this case the 7 face is surrounded by (9, 11, 13).

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: