Enigmatic Code

Programming Enigma Puzzles

Enigma 1138: Pedal power

From New Scientist #2294, 9th June 2001 [link]

Jane left the campsite and cycled north at her own steady speed. At the same time Mark left the campsite and cycled south at a speed one mile per hour faster than Jane.

An hour later I realised that they had left without their packed lunches. So, at my own steady speed of 10 miles an hour, I cycled after Jane, gave her a packed lunch, turned round and cycled after Mark, gave him a packed lunch, and then turned round and cycled back to the campsite.

The round trip took me 5 hours. How long would it have taken if I had cycled to Mark first and then to Jane?



One response to “Enigma 1138: Pedal power

  1. Jim Randell 5 December 2016 at 8:01 am


    If I travel at speed v, to catch up a cyclist travelling at speed x, with a head start of h (time), then we meet at a distance d and time t where:

    d = x . t
    d = v (t − h)

    t = v h / (v − x), d = v x h / (v − x)

    And it takes me the same time to get back, so the total time to deliver the lunch to this cyclist and return is:

    T(x, v, h) = 2(t − h) = 2((v h / (v − x)) − h) = 2 x h / (v − x)

    Now considering two cyclists with speeds a and b, to deliver to the first cyclist (and return) would take:

    Ta = T(a, v, h) = 2 a h / (v − a)

    And then the second cyclist now has a head start of h + Ta, so to deliver to him (and return) will take:

    Tb = T(b, v, h + Ta) = 2 b (h + Ta) / (v − b) = 2 b h (v + a) / ((v − a)(v − b))

    and the total time is:

    T = Ta + Tb = 2 v h (a + b) / ((v − a)(v − b))

    We notice that this is symmetrical in terms of a and b, so in terms of total time it doesn’t matter which cyclist we visit first. And in general this is true regardless of the speeds and head start involved. So without further calculation we know that the answer to the puzzle is 5 hours.

    Solution: It would also have taken 5 hours to cycle to Mark first, and then Jane.

    In this particular case we have:

    T = 5, v = 10, h = 1, b = a + 1

    which gives:

    5 = 2 . 10 . 1 . (a + (a + 1)) / ((10 − x) (10 − (a + 1)))
    a² − 27a + 86 = 0
    a = (27 ± √385) / 2

    a ≈ 3.69, a ≈ 22.31

    We need the smaller solution, as June’s speed must be less than 10 mph in order for us to catch up with her (indeed it must be less than 9 mph in order for us to catch up with Mark, who is travelling 1 mph faster).

    However, although it doesn’t make any difference to the overall time (or distance travelled) which cyclist we deliver to first, if we deliver to the slower one first (Jane) then the lunches are delivered sooner:


    Visiting the slower cyclist first the packed lunches are delivered at 1h35m and 4h05m after they set out, with the alternative strategy they are delivered at 1h53m and 4h23m.

    Here is a numeric program that calculates the speeds of Jane and Mark (using the find_value() solver from the enigma.py library) and then uses these to compute the time it would have taken to visit them in the opposite order. It runs in 40ms

    from enigma import find_value, printf
    # time taken to deliver lunch at a speed of <v> to a cyclist
    # travelling at speed <x> with a head start of <h>
    def T(x, v, h):
      return 2 * x * h / (v - x)
    # my velocity and start time
    (v, h) = (10.0, 1.0)
    # time taken to deliver the two lunches to cyclists with speeds a and b (in that order)
    def time(a, b):
      # first deliver to A
      Ta = T(a, v, h)
      # then deliver to B
      Tb = T(b, v, h + Ta)
      # return the total time taken
      return Ta + Tb
    # time to deliver the two lunches, parameterised by jane's speed
    fn = lambda x: time(x, x + 1.0)
    # find when the time taken is 5 hours
    r = find_value(fn, 5.0, 0.0, 9.0)
    # determine jane's speed from the result
    j = r.v
    # calculate mark's speed
    m = j + 1.0
    # calculate the time taken to deliver to mark first, then jane
    t = time(m, j)
    # output the answer
    printf("jane's speed = {j:.6f} mph, mark's speed = {m:.6f} mph, alternate time = {t:.6f} hours")

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: