# Minecraft Calculus: River Crossing Escape

This is a classic introductory calculus problem, with a Minecraft theme.  This particular variation is inspired by example 4 in section 4.5 of Stewart's calculus.

I'll set the scene:  You're weaponless.  You have half a heart and you're being chased by a skeleton archer.  There's a river between you and your cabin.  You need to get to your cabin as quickly as possible!

In more "mathy" terms, you want to get from $A$ to $B$.  There are three main ways you can do this:

1. $A$ to $B$ directly, diagonally across the river
2. $A$ to $C$ and then $C$ to $B$
3. At slight angle from $A$ to $D$ and then $D$ to $B$

We know that swimming is slower than running, so option 1 isn't the best.  Option 2 involves the smallest time in the water, but also the longest distance traveled.

Option 3 is somewhere in between - you spend a bit more time in the water, but the total distance is decreased.  The travel time in this case depends on where exactly point $D$ is.  To find the optimal path, we must find the position of $D$ which minimizes the travel time.  This sounds like calculus!

Let $x$ be the distance between points $C$ and $D$.  In math terms, $|CD|=x$.

We first need an expression for the total time traveled in terms of $x$.  The basic equation for time traveled at constant speed is

$t=\frac{distance}{speed}$.

The first part of the trip is in the water where we travel from $A$ to $D$.  We can use Pythagorean's theorem to get this distance as $|AD|=\sqrt{x^2+w^2}$.  Assuming that we can travel at a speed of $v_w$ in the water, the time for this part is

$t_w=\frac{\sqrt{x^2+w^2}}{v_w}$.

The land part of the trip involves traveling what's left over of $l$ after having already traveled $x$, so $|DB|=l-x$.  Traveling at $v_l$ on land, the time for this part of the trip is

$t_l=\frac{l-x}{v_l}$.

The total trip time, $T(x)$, is just the sum of these two.

$T(x)=\frac{\sqrt{x^2+w^2}}{v_w}+\frac{l-x}{v_l}$     (1)

To optimize this function with respect to $x$, we need to find where it is stationary and then verify that this point is a minimum.  This means we want to find a place where the function isn't changing with small changes in $x$.  In other words, we want to find a spot where the derivative is zero.

Taking the derivative gives:

$T'(x)=\frac{x}{v_w\sqrt{x^2+w^2}}-\frac{1}{v_l}$

Setting this equal to zero, we can solve for $x$:

$x=\frac{v_ww}{\sqrt{v_l^2-v_w^2}}$     (2)

Let's plug in some numbers!  In Minecraft, you can swim at about 2.2 m/s and sprint at 5.6 m/s.  Let's take the river width $w$ to be 7 blocks (1 block = 1 meter).  Plugging in, we find that $x=2.9$.  At this point, though, we can't tell if this is a maximum or a minimum.  One way to find out is to examine the curvature of the function at this point by using the 2nd derivative:

$T''(x)=\frac{1}{v_w\sqrt{x^2+w^2}}(1-\frac{x^2}{x^2+w^2})$

Plugging in $x=2.9$, we see that $T''(2.9)=0.04$ which, being positive, means that $x=2.9$ is a minimum point for $T(x)$.  Visually:

So if you want to get to your cabin as quickly as possible, the fastest route is to swim across the river to a point $D$ that is 2.9 meters from point $C$ and then run the rest of the way.

This is actually a general problem.  Try replacing the speeds I used with speeds for soul sand, crouching and walking, a boat, etc. and see what happens!  Particularly, what happens to (2) if you can travel more quickly in the water than on land?

#### Scratch Work

Finding $T'(x):$  First, rewrite the square root as a power,  $T(x)=\frac{(x^2+w^2)^{\frac{1}{2}}}{v_w}+\frac{l-x}{v_l}$

Differentiating, using the chain rule on the first term,  $T'(x)=\frac{\frac{1}{2}(x^2+w^2)^{-\frac{1}{2}}(2x)}{v_w}-\frac{1}{v_l}=\frac{x}{v_w\sqrt{x^2+w^2}}-\frac{1}{v_l}$

Finding $T''(x):$  Starting with $T'(x)=\frac{(x^2+w^2)^{-\frac{1}{2}}x}{v_w}+\frac{1}{v_l}$, we differentiate with respect to x.  Note that the derivative of $\frac{1}{v_l}$ with respect to $x$ is 0, so we only have to deal with the first term.  Using the product rule and chain rule:

$T''(x)=\frac{-\frac{1}{2}(x^2+w^2)^{-\frac{3}{2}}(2x^2)}{v_w}+\frac{(x^2+w^2)^{-\frac{1}{2}}}{v_w}$

Cleaning up with some algebra:

$T''(x)=\frac{-x^2}{v_w(x^2+w^2)^{\frac{3}{2}}}+\frac{1}{v_w\sqrt{x^2+w^2}} =\frac{1}{v_w\sqrt{x^2+w^2}}(1-\frac{x^2}{x^2+w^2})$

1. Mmmm, I don't know. The picture features a river that you can block run across 😛

pfft, maths