# A fun Valentine's day chocolate box optimization problem…

Today I received a small box with chocolate almonds in it. Here's a photo: The top and bottom of the box are held together by a band that "cuts across" alternating corners. It got me thinking: ha, I'll make this into a fun little calculus optimization problem: what distance $x$ from the corner should the band cross each edge as to minimize the total length of the band? And more specifically, what is this distance in terms of the length, width, and height of the box?

We're defining $x$ as the following (view from the top of the box, bands are red): Let's call $b_T$ the total band length, $b_h$ the sum of the portions of the band on the top and bottom of the box, $b_l$ the sum of the portions of the band on the side $l$ of the box, and $b_w$ the portions of the band on the side $w$ of the box. And of course, $b_T = b_h + b_l + b_w$.

Considering just the top and bottom, we can see:

$b_h = 4x\sqrt2$.

Similarly, since the total side length of two sides of the box are $l$ and the other two are $w$, and the height of the box is $h$, using the Pythagorean Formula we can get the following two formulas:

$$b_w=2\sqrt{h^2+(w-2x)^2}$$

$$b_l=2\sqrt{h^2+(l-2x)^2}$$

Thus, our total band length in terms of x is:

$$b_T = 4x\sqrt2 + 2\sqrt{h^2+(w-2x)^2} + 2\sqrt{h^2+(l-2x)^2}$$

Since this is an optimization problem and we wish to find the minimum value of $b_T$, we will differentiate and set equal to zero:

$$b_T' = 4\sqrt2 + \frac{-4(w-2x)}{\sqrt{h^2+(w-2x)^2}} + \frac{-4(l-2x)}{\sqrt{h^2+(l-2x)^2}}$$

$$0 = 4\sqrt2 + \frac{-4(w-2x)}{\sqrt{h^2+(w-2x)^2}} + \frac{-4(l-2x)}{\sqrt{h^2+(l-2x)^2}}$$

By rearranging a bit more, we can rationalize it to:

$$\left(2+ \frac{(w-2x)^2}{h^2+(w-2x)^2} - \frac{(2x-l)^2}{h^2+(l-2x)^2}\right)^2 = \frac{8(w-2x)^2}{h^2+(w-2x)^2}$$

Remember, the goal is to find, given the dimensions of the box, some optimum placement of the band. So we need to rearrange this formula to get $x$ in terms of $l$, $w$, and $h$. This is where I am at a total loss. Distributing out the left side would give us too many terms to keep track of; even substituting each terms for $a$, $b$, and $c$ respectively, distributing that, and then plugging back in results in a ridiculous number of terms. This would be absurd; how can we do this a better way and get $x$ in terms of $l$, $w$, and $h$?

(Also, I hope I haven't messed up any of the formulas while typesetting them. I don't think I did, but you never know...)

• Nice problem. For a sanity check, solve the problem when $h=0$, perhaps when $w = l$ as in your picture. – Ethan Bolker Feb 14 '18 at 22:04
• @willem.hill: Awesome, you got a math problem for Valentine's Day! I am so jealous! – Moo Feb 14 '18 at 22:07
• @EthanBolker Thanks, just confirmed that I've done it correctly (after just adding in a couple 2's)... both things you've suggested check out in Desmos... – willem.hill Feb 14 '18 at 22:21
• A Desmos link to play with: desmos.com/calculator/9f2tgs2rri – willem.hill Feb 14 '18 at 22:26

## 1 Answer

My intuition says that this should be the diagram. This means that the optimal band will not cross the top at a $45^{\circ}$ angle, unless the box has a square top. Otherwise, the line has a slope equal to $\frac {w+h}{l+h}$ and has total length.

The length marked off by the right triangle goes from the middle of the front tot the middle of the side. Its length is $\sqrt { (\frac {w+h}{2})^2 + (\frac {l+h}{2})^2}$ and is $\frac 14$ the total length of the band.

$2\sqrt {(l+h)^2 + (w+h)^2}$

On further thought... doesn't change the answer, but it does introduce a small nuance.

The band travels across the top twice and the bottom twice and each side once.

Figure 2. The shortest distance is a straight line, and the dimensions the line must cross is $(2h + 2w) \times (2h + 2l)$

However, there is nothing that says the shortest distance is in fact symmetric in the way it crosses top and bottom.

• Ouch, thanks for pointing out that it won't cross the top at a 45º angle... that certainly does add a level of complexity that I didn't before consider... – willem.hill Feb 14 '18 at 22:50
• It actually takes down the complexity. – Doug M Feb 14 '18 at 22:54