Enigmatic Code

Programming Enigma Puzzles

Enigma 146: Around the clock

From New Scientist #1291, 4th February 1982 [link]

I recently amused my son with a little numerical pastime. I drew a circle and marked 12 equally spaced points around the circumference. By each of the points I wrote a digit: each of the digits from 0 to 9 occurred somewhere (and, of course, there were some repeats).

The exercise consisted of starting at the centre of the circle, drawing a straight line to one of the 12 points on the circumference, drawing another straight line from there to another of the 12 points, a line from there to another of the 12 points, and finally a line from there to another of the 12 points. We would then look at the four-figure number “spelt out” (we never started with a zero). We’d then start again at the centre.

With one such sheet we did three similar exercises. The four-figure numbers spelt out were, respectively:

a product of five consecutive integers;
a number divisible by 7, 11 and 13;
an odd perfect cube.

By coincidence each of the straight lines drawn in obtaining these three numbers was a whole number of inches long.

What was the perfect cube?


2 responses to “Enigma 146: Around the clock

  1. Jim Randell 18 November 2013 at 8:11 am

    I found this puzzle more convoluted to solve than I was expecting. A bit of analysis leads to an approach that gives a program that runs in a reasonable time. This Python 3 program runs in 74ms.

    # the first line drawn is the radius of the circle, so that must be an
    # integer
    # subsequent lines are between points on the circumference
    # if we start at 12 o'clock only lines to 2 o'clock, 6 o'clock and 10
    # o'clock are rational multiples of the radius (and they are actually
    # integer multiples), so the numbers are divided into two disjoint
    # orbits (odd positions and even positions) and the digits for each
    # number are drawn from one of those orbits
    # numbers are confined to their own orbit, at each stage you progress
    # by moving to a number that differs by 1 or 3 positions
    from itertools import count, product
    from collections import Counter
    from enigma import multiply, diff, printf
    # find 4-digit numbers that are...
    def digits(i, d=4):
      for n in i:
        s = str(n)
        l = len(s)
        if l < d: continue
        if l > d: break
        yield s
    # ... the product of 5 consecutive integers
    def gc5():
      ns = []
      for n in count(1):
        if len(ns) > 5:
        if len(ns) == 5:
          yield multiply(ns)
    c5 = list(digits(gc5(), 4))
    printf("[c5 = {c5}]", c5=', '.join(c5))
    # ... multiples of 7 * 11 * 13 = 1001
    def gm1001():
      for n in count(1):
        yield 1001 * n
    m1001 = list(digits(gm1001(), 4))
    printf("[m1001 = {m1001}]", m1001=', '.join(m1001))
    # ... odd perfect cubes
    def gcubes():
      for n in count(1, step=2):
        yield n ** 3
    cubes = list(digits(gcubes(), 4))
    printf("[cubes = {cubes}]", cubes=', '.join(cubes))
    # check an orbit
    def check(d, n=None, r=None):
      # check the number of elements
      if n is not None and sum(d.values()) > n:
        return False
      # and the number of repeated elements
      if r is not None and sum(v - 1 for v in d.values() if v > 1) > r:
        return False
      # seems OK
      return True
    # fit a number into an orbit
    # n - number to fit
    # ds - digits of the orbit (or None)
    # ps - positions used in the orbit
    def fit(n, ds, ps):
      # are we done?
      if not n:
        yield ds
      # if the orbit is empty
      if ds is None:
        # create a new orbit
        (ds, ps, n) = ([n[0]] + [None] * 5, [0], n[1:])
      # possible next positions
      if not ps:
        qs = (0, 1, 2, 3, 4, 5)
        qs = diff([(ps[-1] + d) % 6 for d in (1, 3, 5)], ps)
      # fit the next digit
      for q in qs:
        ds1 = ds
        if ds[q] is None:
          ds1 = list(ds)
          ds1[q] = n[0]
        elif ds[q] != n[0]:
        yield from fit(n[1:], ds1, ps + [q])
    # generate orbits for the specified numbers
    # ns - numbers to fit in the orbit
    # ds - digits of the orbit
    def orbits(ns, ds):
      if not ns:
        # check the orbit doesn't exceed the repeat count
        if check(Counter(ds), r=2):
          yield ds
        # fit the first number into the orbit
        (n, *ns) = ns
        for ds1 in fit(n, ds, []):
          yield from orbits(ns, ds1)
    # record possible cubes
    r = Counter()
    # choose a number from each of the candidates
    for (a, b, c) in product(c5, m1001, cubes):
      # try to fit all three numbers fit in a single orbit
      d = Counter(a) | Counter(b) | Counter(c)
      if check(d, n=6, r=2):
        # find a possible orbit
        for ds in orbits([a, b, c], None):
          r[c] += 1
          printf("[({a}, {b}, {c}), orbit={ds}]", ds=''.join(ds))
      # try to fit two numbers into one orbit
      for z in (a, b, c):
        (x, y) = diff([a, b, c], [z])
        d = Counter(x) | Counter(y)
        if check(d, n=6, r=2):
          # and would the other number exceed the repeat count?
          if check(d + Counter(z), r=2):
            # find a possible orbit for the pair
            for ds in orbits([x, y], None):
              r[c] += 1
              printf("[({a}, {b}, {c}), pair=({x}, {y}), orbit={ds}]", ds=''.join(ds))
    # print the results
    for (k, v) in r.most_common():
      printf("cube={k} [{v} solutions]")

    Solution: The perfect cube is 4913.

    You can remove the code from my program that constructs the orbits and you find that there are four candidate triples and each of them use the same perfect cube. But for two of these candidates it is not possible to construct a clock face corresponding to the problem statement. So in order to fully solve the problem it is necessary to show that a clock face can be constructed for at least one of the candidate triples. In fact, two of them are possible, and there are many different ways to construct the clock face for each solution.

    • Hugh Casement 2 August 2015 at 9:17 am

      As you point out in the comment lines of the program, the digits fall into not just “two sets of six” as the solution published in the magazine said, but two overlapping hexagons. Each 4-digit number can use digits from one set only.

      If each of 0 – 9 occurs at least once, at most two are repeated.  7×11×13 = 1001 and all its 4-digit multiples have 00 in the middle, so that is one of the repeated digits.  The other falls in the same set.

      The product of five consecutive integers can only be 3×4×5×6×7 = 2520 (in which case 2 is also repeated) or 4×5×6×7×8 = 6720.  The odd perfect cube cannot be 1331 for that would require a third repeated digit.  It must be the cube of an odd number from 13 to 21.

      The solution I found, clockwise from the 12 o’clock position, is:
      4 6 9 7 1 2 3 0 8 0 5 2.
      4913 reads clockwise from 12 o’clock, 6720 clockwise from 1 o’clock, 2002 clockwise from 5 o’clock or anticlockwise from 11 o’clock.  No doubt there are other arrangements, not just rotations and reflexions of that.

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: