If you find this page helpful and would recommend that I create more pages like this one, please let me know: Email to John Taylor
Towns A and B are on opposite sides of a ridge.

We can describe the situation as in the diagram. Let H be the length of the tunnel portion, 5 – L be the length of the level portion beside the ridge. We can express the total cost in terms of the lengths 5 – L and H and the cost per mile of each type of construction. Using millions of dollars:

We want to minimize the cost. In order to do so, we need to express it in terms of a single variable. H, L and the 0.5 mile distance are related by the Pythagorean Theorem:
.
With this result, we can express the cost entirely in terms of the length L:

Now we can differentiate with respect to L and find the value of L which minimizes the cost.
In general,
![]()
At the minimum,
![]()
Collecting the dependence on Lmin on one side, we get

We can square both sides to get
,
or 
Solving, we get
,
or ![]()
Hence,
![]()
The corresponding cost is

For comparison, when L is 0.15, the cost is 3.469 million,
and when L is 0.11, the cost is 3.469 million.