Enigmatic Code

Programming Enigma Puzzles

Enigma 1761: Clock work

From New Scientist #2929, 10th August 2013 [link]

The clock in Simpson Mall has hour, minute and second hands. Little Esu climbs onto the hour hand at 12.01 pm, and stays on it until the minute and hour hands are aligned. At that instant, Esu jumps on to the minute hand and rides on it until the hour and minute hands are aligned and then jumps on to the hour hand. In this way, Esu changes positions between the hour and minute hands whenever they are aligned. Finally, Esu jumps off the clock when all three hands are aligned.

For how many minutes in total did Esu ride the minute hand?



2 responses to “Enigma 1761: Clock work

  1. Jim Randell 7 August 2013 at 6:50 pm

    I used a similar technique to Enigma 93 for this one (and reused some of the code). I’m assuming the hands being “aligned” means on top of each other (which is the only way I can think of all three hands being “aligned”), and that the hands move continuously and smoothly.

    This Python program constructs Esu’s journey (although with a bit of analysis there is a much easier way to get the answer). This program runs in 59ms.

    from fractions import Fraction as F
    from collections import namedtuple
    from enigma import sprintf, irange, printf
    Time = namedtuple('Time', 'h m s')
    # positions of the hour, minute, second hands at time t
    def hms(t):
      h = t - int(t)
      m = 12 * h - int(12 * h)
      s = 60 * m - int(60 * m)
      return Time(h, m, s)
    # format the positions as a readable time
    def fmt(p):
      h = int(12 * p.h)
      if h == 0: h = 12
      m = int(60 * p.m)
      s = float(60 * p.s)
      return sprintf("{h:02d}:{m:02d}:{s:09.6f}")
    # start at 12:01, accumulate time spent on the minute hand
    (t0, m) = (F(1, 12 * 60), 0)
    # the minute and hour hands coincide 11 times in 12 hours
    for i in irange(1, 11):
      t = F(i, 11)
      p = hms(t) # calculate the position of the hands
      assert p.m == p.h # the hour and minute hands should be coincident
      d = t - t0 # compute the time difference
      printf("[time: {t0} - {t}, delta = {d}, hand = {h}]", t0=fmt(hms(t0)), t=fmt(hms(t)), d=fmt(hms(d)), h=['minute', 'hour'][i % 2])
      if i % 2 == 0: m += d # accumulate time on the minute hand
      if p.s == p.m == p.h: break # stop when all hands are aligned
      t0 = t
    printf("cumulative time on minute hand = {m}", m=fmt(hms(m)))

    Solution: Esu was on the minute hand for 327 and 3/11 minutes.

    • Jim Randell 19 September 2013 at 10:10 am


      The hour and minute hands coincide 11 times in a 12 hour period. 12:00:00 is the only time all three hands are coincident. Esu is on the minute hand in the 2nd and then every other eleventh (which excludes the 1st eleventh from consideration, which is 1 minute shorter than the rest), of which there are five. So Esu is on the minute hand for 5/11 of the 12 hour period, and the answer follows with a simple calculation.

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: