# Sharing a Bicycle

**URL:** <https://community.wolfram.com/t/sharing-a-bicycle/13253>\
**Category:** Staff Picks\
**Tags:** fun-and-play, graphics-and-visualization, modeling, staff-pick\
**Created:** [October 28, 2018, 4:27pm UTC](https://community.wolfram.com/t/sharing-a-bicycle/13253 "2018-10-28T16:27:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jashonder](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/jashonder/32/26540_2.png) [@jashonder](https://community.wolfram.com/u/jashonder)\
**Post date:** [October 28, 2018, 4:27pm UTC](https://community.wolfram.com/t/sharing-a-bicycle/13253/1 "2018-10-28T16:27:10Z")

</div>

**[Open in Cloud](https://www.wolframcloud.com/objects/wolfram-community/Sharing-a-Bicycle-by-John-Shonder) | Download to Desktop via Attachments Below**

 ![ScreenShot2018-11-08at8.34.19PM.jpg](https://global.discourse-cdn.com/wolfram/original/3X/d/8/d8d0f019898c8155f675c41035a9507f6df8f090.jpeg)

The following question appeared in Parade Magazine’s Ask Marilyn column for Sunday, May 2, 2010:

> A friend and I once went from his house to mine with one bicycle. I started walking and he rode the bike. When he got a couple of blocks ahead, he left the bike on the sidewalk and started walking. When I got to the bike, I started riding, passing him, and then left the bike a couple of blocks ahead. When he got to the bike, he started riding. We did this the whole way.

> 

> At least one of us was always walking. At times, one was riding; at other times, we were both walking. I’m sure this was faster than if we had no bike. But some people insist that it was no faster because somebody was always walking. Who’s right?

> 

> Marilyn’s answer was: “The reader is right. It’s true that someone was always walking. But neither friend walked the whole distance. Both biked part of the way. This increased their average speed, so they saved time.”

As with the Monty Hall problem, numerous readers wrote in to disagree with Marilyn, insisting that since someone was always walking, the journey could be no faster than if both had walked the entire distance. What do you think?

Designating the two friends as A and B, the situation is as follows (assuming A has the bike first):

1. A rides the bike and B walks, until A is a fixed distance h ahead of B, at which time A dismounts and leaves the bike on the sidewalk.

2. A and B walk until B comes to the bike, at which time B picks it up.

3. B rides the bike and A walks, until B is a distance h ahead of A, at which time B dismounts and leaves the bike on the sidewalk.

4. A and B walk until A gets to the bike, at which time A picks it up.

Step 1 follows Step 4, and the steps repeat sequentially until the last friend reaches the other house.

In his book [Number-Crunching:Taming Unruly Computational Problems from Mathematical Physics to Science Fiction](https://books.google.com/books/about/Number_Crunching.html?id=pxz8G-KF3ZgC) (which I highly recommend), Paul Nahin presents a Matlab program to simulate this problem. The program uses a discrete time step, and it occurred to me that with careful bookkeeping, the finish time (i.e., the time for the last friend to reach the house) could be calculated exactly. I decided to write my own simulation using Wolfram Mathematica. To begin, I define the following terms:

_d_: Distance between the two houses

_h_: Distance ahead, i.e., the rider leaves the bike this distance ahead of the walker

_rA_: Speed at which A rides the bike

_wA_: Speed at which A walks

_rB_: Speed at which B rides the bike

_wB_: Speed at which B walks

_t_ : Time

\Delta_t_: Time increment

I also made the assumption that both friends are able to ride the bicycle faster than they walk, i.e., rA \> wA and rB \> wB.

In general, at the beginning of any step, A is at _xA_ and B is at _xB_. At the end of the step, A is at _xA_ + _vA$\Delta$t_ and B is at _xB_ + _vB$\Delta$t_, where A’s velocity _vA_ is either _wA_ or _rA_ depending on the particular step; B’s velocity _vB_ is either _wB_ or _rB_; and \Delta_t_ is calculated from the velocities and distances particular to that step. We must then check whether either of the two friends will reach the other house before \Delta_t_ elapses.

The calculations for each step are as follows:

###Step 1

When Step 1 is completed, A is _h_ units ahead of B. Since A is riding the bike and B is walking, we have the equation _xA + rA__·$\Delta$t = xB + wB·$\Delta$t + h_. Solving for \Delta_t_ gives \Delta_t = (xB - xA + h) / (rA - wB)_. Thus at the end of Step 1, A is at _xA + rA__·$\Delta$t_, B is at _xB + wB__·$\Delta$t_, and the time is incremented by \Delta_t_. A then puts down the bicycle.

Of course if _rA_ \leq _wB_ then A will never catch up with B. The distance _h_ essentially drops out of the problem, and the completion time is the time for A to ride the bike the entire distance _d._

If _xA + rA__·$\Delta$t \> d_ or _xB + wB·$\Delta$t \> d_ then one of the friends will reach the other house before the end of the time step. We must determine which friend arrives first; the total time for the journey is then the time at the beginning of Step 1 plus the time required for the other friend to reach the end of the journey_._

###Step 2

In Step 2, B walks the distance _h_ and reaches the bike. This takes _$\Delta$t_ = _h/wB_ time units. At the end of Step 2, B is at _xB + h_, A is at _xA + wA__·$\Delta$t_, and the time is incremented by _$\Delta$t_.

If _xA + wA__·$\Delta$t \> d_, then A reaches the other house on this step. The total time for the journey is then the current time plus the time required for B to get to the bike and ride it to the other house.

###Step 3

Step 3 is identical to Step 1, except that B is riding the bike and A is walking. Reasoning as in Step 1, we find _$\Delta$t = (xA - xB + h) / (rB - wA)_. So at the end of Step 3, A is at _xA + wA __·$\Delta$t,_ B is at _xB + rB__ ·$\Delta$t,_ and the time increments by _$\Delta$t_.

As in Step 1, if _rB_ \leq _wA_ then B will never catch up to A, and the completion time is then the current time plus the time required for B to complete the journey on the bike.

If _xA + wA __·$\Delta$t \> d_ or _xB + rB__ ·$\Delta$t \> d,_ then one of the friends reaches the other house on this step. As in step 1, we determine which friend arrives first. The total time for the journey is then the time at the beginning of Step 3 plus the time required for the other friend to reach the other house. The time increments by _$\Delta$t_.

###Step 4

Step 4 is identical to Step 2, except that A walks the distance _h_ and reaches the bike. This takes _$\Delta$t_ = _h/wA_ time units. At the end of step 2, A is at _xA + h_, B is at _xB + wB·$\Delta$t_, and the time is incremented by _$\Delta$t_.

However, if _xB + wB·$\Delta$t \> d_ then B reaches the other house before A reaches the bike. So the total time to complete the journey is the time at the beginning of Step 4 plus the time required for A to get to the bike and ride it to the second house.

Finally we can translate these equations and conditions into the Wolfram language and write a function to determine the total time of the journey given _wA_, _wB_, _rA_, _rB_, _d_, and _h_:

```
tFinal[wA_, rA_, wB_, rB_, d_, h_] :=
 Block[{t = 0, xA = 0, xB = 0, xC = 0, dt, dt2, dt4},
       dt2 = h/wB; dt4 = h/wA;
  While[True,
   (* Step 1 *)
   If[rA <= wB, Return[d/rA]];
   dt = (h + xB - xA)/(rA - wB);
   If[(xA + rA dt >= d ) || (xB + wB dt >= d), 
    If[(d - xA)/rA < (d - xB)/wB, Return[t + (d - xB)/wB], 
     Return[t + (d - xA)/rA]]];
   xA += rA dt; xB += wB dt; xC = xA; t += dt;
   (* Step 2 *)
   dt = dt2;
   If[xA + wA dt > d, Return[t + dt + (d - xC)/rB]];
   xA += wA dt; xB += h; t += dt;
   (* Step 3 *)
   If[rB <= wA, Return[t + (d - xB)/rB]];
   dt = (h + xA - xB)/(rB - wA);
   If[(xB + rB dt >= d ) || (xA + wA dt >= d), 
    If[(d - xB)/rB < (d - xA)/wA, Return[t + (d - xA)/wA], 
     Return[t + (d - xB)/rB]]];
   xB += rB dt; xA += wA dt; xC = xB; t += dt;
   (* Step 4 *)
   dt = dt4;
   If[xB + wB dt >= d, Return[t + dt + (d - xC)/rA]];
   xA += h; xB += wB dt; t += dt;]]

```

With this function we can reproduce Nahin’s figure 7.2.2, with _d_ = 1 mile, _wA_ = _wB_ = 2 miles per hour, and _rA_ = _rB_ = 6 miles per hour:

```
d = 5280.; wA = wB = 2*5280/3600; rA = rB = 6*5280/3600;
    Plot[tFinal[wA, rA, wB, rB, d, h], {h, 10, 1500}, Frame -> True, 
         FrameLabel -> {"Separation (feet)", 
           "Time for second friend to finish (seconds)"}, 
         LabelStyle -> Directive[Larger], GridLines -> None, 
         ImageSize -> Large, PlotLabel -> "Figure 1"]

```

 ![Figure1.jpg](https://global.discourse-cdn.com/wolfram/original/2X/e/ec2fc272df81859abd8205d9d91cc7287fca30ac.jpeg)

Given their walking speed of 2 miles per hour, it would take the friends 30 minutes = 1800 seconds to cover a distance of one mile without the bicycle. Figure 1 shows that there are values of _h_ that result in times as low as 1200 seconds. Clearly, sharing the bicycle makes the journey faster. Marilyn Vos Savant was correct!

[Sharing-a-Bicycle-by-John-Shonder.nb](https://community.wolfram.com/uploads/short-url/xCbZOaQR7dhMRexOyLzXcwej75e.nb) (57.7 KB)

---

<div class="post-metadata">

**Author:** ![wolframcommunity](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/wolframcommunity/32/8335_2.png) [@wolframcommunity](https://community.wolfram.com/u/wolframcommunity)\
**Post date:** [November 9, 2018, 2:23am UTC](https://community.wolfram.com/t/sharing-a-bicycle/13253/2 "2018-11-09T02:23:39Z")

</div>

![2015-11-02_10-07-11.png](https://global.discourse-cdn.com/wolfram/original/3X/5/0/50e59c9ead62f729e7130d3ea1482555a75602b6.png)

- Congratulations! This post is now a [Staff Pick](http://community.wolfram.com/content?curTag=staff+picks) as distinguished by a badge on [your profile](http://community.wolfram.com/web/jashonder)! Thank you, keep it coming, and consider contributing your work to the [The Notebook Archive](http://notebookarchive.org/)!
