# Enigmatic Code

Programming Enigma Puzzles

## Enigma 296: Quite a coincidence

From New Scientist #1444, 21st February 1985 [link]

I had a noon appointment in town and decided after a leisurely breakfast to get an appropriate train for the precisely 19 mile rail journey.

As the train drew out of the station I noticed on my very accurate watch that the departure was exactly on time.

As we arrived at the London terminus I noticed that the hour and minute hands on my watch were exactly coincident. I calculated that the train have averaged a whole number of miles per hour for my journey.

What time did the train depart and what was its average speed?

[enigma296]

### One response to “Enigma 296: Quite a coincidence”

1. Jim Randell 20 July 2015 at 9:19 am

See also Enigma 93 and Enigma 1761 for other puzzles involving coincident clock hands.

This Python program generates possible average speeds, departure and arrival times for the train (we assume the train does not arrive at exactly noon). It runs in 237ms.

We can then choose the most reasonable looking solution.

```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
# t, h, m, s are measured as fractions of a 12-hour clock face
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}")

# the minute and hour hands coincide 11 times in 12 hours
for i in irange(1, 10):
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

# consider possible average speeds for the train
for s in irange(1, 200):
# the departure time would be...
d = hms(t - F(19, 12 * s))
if d.s == 0:
printf("speed = {s} mph, departure = {d}, arrival = {t}", d=fmt(d), t=fmt(p))
```

Solution: The train departed at 10:20am, and travelled at an average speed of 33 mph.

The train arrives at (around) 10:54:33am, which leaves over an hour to get to the appointment.

There are other possible solutions though, but perhaps they are less reasonable.

The train could arrive at (around) 8:43:38am, which leaves more than three hours to get to the appointment. The departure time of the train could either be 7:00am, with the train travelling at an average speed of 11 mph. Or the train could leave at 8:35am and travel at an average speed of 132 mph. We might consider that these departure times do not allow for a leisurely breakfast (although that presumably depends on what time you get up).

And there are possible earlier arrival times for the train. So perhaps the setter could have been more explicit about what time he finished breakfast.

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