# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1070: Time to work

From New Scientist #2226, 19th February 2000 [link]

Amber cycles a distance of 8 miles to work each day, but she never leaves home before 0730h. She has found that if she sets off at x minutes before 0900h then the traffic is such that her average speed for the journey to work is (10 − x/10) miles per hour. On the other hand, if she sets off at x minutes after 0900h then her average speed is (10 + x/10) miles per hour.

(1) Find the time, to the nearest second, when Amber should set off in order to arrive at work at the earliest possible time.

Matthew lives in another town but he also cycles to work, setting off after 0730h, and he has found that his average speed for the journey to work follows exactly the same pattern as Amber’s. He has calculated that if he sets off at 0920h then he arrives at work earlier than if he sets off at any other time.

(2) How far does Matthew cycle to work?

[enigma1070]

### 3 responses to “Enigma 1070: Time to work”

1. Jim Randell 19 March 2018 at 8:01 am

I solved this puzzle using the [[ `find_min()` ]] numerical solver in the enigma.py library.

This Python program runs in 81ms.

Run: [ @repl.it ]

```from enigma import find_min, sprintf, printf

# format time x (minutes after 9am)
def time(x):
x += 540.0
h = int(x) // 60
x -= 60.0 * h
m = int(x)
s = (x - m) * 60.0
return sprintf("{h:02d}:{m:02d}:{s:05.2f}")

# speed if setting off at x minutes after 9am
v = lambda x: (10.0 + x / 10.0)

# function to return arrival time for cycling distance d (miles)
# (setting off at x minutes after 9am)
def f(d):
return lambda x: x + 60.0 * d / v(x)

# find a minimum start time for cycling distance d
def fmin(d):
return find_min(f(d), -90.0, 90.0)

# find Amber's minimum start time
r = fmin(8.0)
printf("(1) {start} -> {arrive}", start=time(r.v), arrive=time(r.fv))

# if Matthew cycles d miles, how close is minimum start time to 09:20?
def M(d):
r = fmin(d)
return abs(r.v - 20.0)

# find the closest value to 09:20
r = find_min(M, 0.0, 50.0)
t = fmin(r.v)
printf("(2) distance = {r.v:.2f} miles, {start} -> {arrive}", start=time(t.v), arrive=time(t.fv))
```

Solution: (1) Amber should set off at 08:29:17. (2) Matthew cycles 24 miles to work.

To the nearest hundredth of a second, Amber’s start time should be 08:29:16.92. She will arrive at work at 09:38:33.84.

If Matthew sets off at 09:20, he is cycling at an average speed of 12 mph, so he makes his 24 mile journey in 2 hours and arrives at work at 11:20.

• Jim Randell 19 March 2018 at 9:17 am

The arrival time for Amber t (in minutes after 9am) is given by:

t = (x² +100x + 4800) / (x + 100)

where x is the departure time (in minutes after 9am).

This has a local minimum at:

x = 40√3 − 100 ≈ −30.718
t = 20(4√3 − 5) ≈ 38.564

So Amber should set off at 30.718 minutes before 9am, which we would more normally write as 08:29:17 (to the nearest second).

• Hugh Casement 19 March 2018 at 10:45 am

If the departure time is x minutes after 9, the speed is (100 + x)/600 miles per minute
and the journey time for distance d miles is 600d/(100 + x) minutes.
The arrival time is that plus x.

By differentiating we find a minimum when (100 + x)² = 600d,
so 100 + x = √(600d) and x = √(600d) – 100, which gives us expressions for both speed and times of departure and arrival in terms of x or d, depending on which we already know.

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