Enigmatic Code

Programming Enigma Puzzles

Enigma 977: Walk and drive

From New Scientist #2132, 2nd May 1998 [link]

Anne, Barbara and Christine walk at 4 mph and drive at 48 mph. They have a journey of 24 miles to do but their car only takes 2 people. So Anne sets off walking, while Barbara drives so far with Christine, who then gets out and walks the rest of the journey. Barbara drives back until she meets Anne, picks her up and the drive the rest of the journey. They choose Christine’s dropping place so as to minimise the time taken by the last person to arrive.

1. How many minutes did the last person take for the journey?

Donald, Eric and Frank have to make a journey of 265 miles. They each walk at a speed which is a whole number of mph and the speed of their 2-seater car is a whole number times their walking speed and is less than 50 mph. They use the same plan as the ladies. The last person to arrive takes an odd number of hours for the journey.

2. How many hours did the last person take for the journey?

[enigma977]

One response to “Enigma 977: Walk and drive

  1. Jim Randell 3 January 2020 at 8:51 am

    In general if the total distance is t, and X travels a distance x in the car at a speed of v, and then walks the remaining (t – x) distance at a walking speed of w, then we have a total time of:

    tX = x/v + (t – x)/w

    And if Y walks an initial distance of y and is driven the remaining (t – y) distance then we have:

    y/w = (2d – y)/v
    y = 2dw / (v + w)
    tY = y/w + (t – y)/v

    This Python program finds the minimal times numerically using the [[ find_min() ]] function from the enigma.py library. It runs in 110ms.

    Run: [ @repl.it ]

    from enigma import fdiv, find_min, irange, printf
    
    # if the total distance is t, and X is driven a distance d at speed v
    # and walks the remaining distance at a speed of w,
    # then their total time is:
    def tX(t, v, w, x):
      # X goes a distance of x at v mph and a distance of (t - x) at v mph
      return fdiv(x, v) + fdiv(t - x, w)
    
    # Y starts walking and is picked up after X is dropped off
    def tY(t, v, w, x):
      # A goes a distance of y at w mph and (t - y) at v mph
      y = fdiv(2 * x * w, v + w)
      return fdiv(y, w) + fdiv(t - y, v)
    
    # find the minimum time taken
    def min_time(t, v, w):
      return find_min(lambda x: max(tX(t, v, w, x), tY(t, v, w, x)), 0, t)
    
    # (1) we are given v and w
    r = min_time(24, 48, 4)
    printf("(1) time taken = {r:.2f}min [d={d:.2f}]", r=60 * r.fv, d=r.v)
    
    # (2) consider possible walking speeds
    for w in irange(1, 8):
      # and driving speeds
      for v in irange(2 * w, 49, step=w):
        r = min_time(265, v, w)
        # is it an odd whole number of hours?
        h = int(r.fv + 0.5)
        if not(abs(r.fv - h) < 0.01 and h % 2 == 1): continue
        printf("(2) w={w}, v={v}; time taken = {h}hr [d={d:.2f}]", d=r.v)
    

    Solution: (1) 74 minutes; (2) 53 hours.

    C is dropped off at a distance of 20.8 miles from the start (and has to walk the last 3.2 miles in 48 minutes). A is picked up having walked the first 3.2 miles (in 48 minutes), and everyone arrives together after 74 minutes.

    The men walk at 2mph and drive at 10mph.

    One of the men is dropped off a distance of 198.75 miles from the start (and has to walk the last 66.25 miles in 33 hours, 7½ minutes). Another one of the men has to walk the first 66.25 miles, and is then picked up. They all arrive together after 53 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: