Monday, April 15, 2024

The Great Ellipse Eclipse

[S]uppose you have two congruent ellipses that, together, cover a unit circle (i.e., a circle with radius $1$). These ellipses can have any eccentricity you like, but they must be congruent to each other. What is the smallest possible area one of these ellipses can have, such that they completely cover the circle?

By symmetry (both rotational and optimization-al?), let's assume that we have two congruent ellipses that have parallel major axis along the $y$-axis and are centered at points $(c,0)$ and $(-c,0)$ for some $c > 0.$ That is, let the equations for the ellipses be \begin{align*} \frac{(x-c)^2}{a^2} + \frac{y^2}{b^2} &= 1 \\ \frac{(x+c)^2}{a^2} + \frac{y^2}{b^2} &= 1.\end{align*}

In order to ensure that these two ellipses cover the entire unit circle we would need to make sure that they cover the extreme points, $(\pm 1, 0)$ and $(0, \pm 1)$ (and for good measure that the origin is contained at least one of them). In order for the origin to be contained we can plug in $x=y=0$ and get $$\frac{c^2}{(1-c)^2} \leq 1,$$ or equivalently $2c - 1 \leq 0,$ or $c \leq \frac{1}{2}.$ In order for $(1,0)$ to be contained in the ellipse centered at $(c,0)$ we must have $$\frac{(1-c)^2}{a^2} + \frac{0}{b^2} = 1,$$ or equivalently $a = 1 - c.$ In order for (0,1) to be contained in either ellipse we must have $$\frac{c^2}{(1-c)^2} + \frac{1}{b^2} = 1$$ or equivalently $$b^2 = \frac{1}{1 - \frac{c^2}{(1-c)^2}} = \frac{(1-c)^2}{(1-c)^2 - c^2} = \frac{(1-c)^2}{1-2c},$$ that is, $b = \frac{1-c}{\sqrt{1-2c}}.$

The area of one of the ellipses is $$A(c) = \pi a(c)b(c) = \pi \frac{(1-c)^2}{\sqrt{1-2c}}.$$ Differentiating we get \begin{align*}\frac{\partial}{\partial c} A(c) &= \pi \left(\frac{(1-c)^2}{(1-2c)^{3/2}} + \frac{2(c-1)}{\sqrt{1-2c}} \right)\\ &= \pi\frac{ (1-c)^2 - 2 (1-2c) (1-c) }{(1-2c)^{3/2}}\\ &= \frac{\pi(1-c)(3c-1)}{(1-2c)^{3/2}}.\end{align*} So the unconstrained critical points of $A$ are $c = 1$ and $c = \frac{1}{3}.$ Since we want $c \leq \frac{1}{2},$ we can eliminate the critical point $c = 1,$ and instead need to just test the critical points $c \in \left\{ 0, \frac{1}{3}, \frac{1}{2} \right\}.$ We have $A(0) = \pi,$ and $\lim_{c \uparrow \frac{1}{2}} A(c) = +\infty$ and $$A\left(\frac{1}{3}\right) = \pi \frac{ \frac{4}{9} }{ \sqrt{\frac{1}{3} }} = \frac{4\pi \sqrt{3}}{9} \approx 2.418399....,$$ which is the smallest area of one ellipse of a congruent pair that can cover the unit circle. For completeness, those ellipses are \begin{align*} \frac{ (3x - 1)^2 }{4} + \frac{3y^2}{4} &= 1 \\ \frac{(3x+1)^2}{4} + \frac{3y^2}{4} &= 1\end{align*}

Monday, March 4, 2024

Let them eat equitable cake slices

You and two friends all have March birthdays, so you’ve decided to celebrate together with one big cake that has delicious frosting around its perimeter. To share the cake fairly, you want to ensure that (1) each of you gets the same amount of cake, by area, and (2) each of you gets the same amount of frosting along the cake’s edge. What’s more, you want to cut the cake by starting at a single point inside of it, and then making three straight cuts to the edge from that point.

As shown in the Fiddler email, you know how to make these cuts for circular or square cakes. However, the cake you bought is rectangular, with a length of 20 inches and a width of 10 inches. Using the coordinate system of your choice, describe a way this particular cake can be cut fairly, so that all three of you get the same amount in terms of both area and the cake’s perimeter. Again, there should be three straight cuts emanating from a single point inside the cake.

Let's put the lower left corner of our sheet cake at the origin of the $xy$-plane with opposite corner located at the point $(20,10)$, so that the long 20in side of the cake is parallel to the $x$-axis. Assume that one of the straight cuts ends up hitting the point $(t,0)$ for some $0\leq t\leq 10$. Then since each birthday person needs one third of the perimeter, the other two cuts must hit the perimeter of the sheet cake at $(20,t)$ and $(10-t,10)$.

If start cutting at the central point within the cake $P=P(x,y)$, then the upper right quadrilateral has area \begin{align*}A_1 &= \frac{1}{2} (10+t) (10 - y) + \frac{1}{2} (10 - t) (20 - x)\\& = 150 - 5t -\frac{1}{2} (10-t) x -\frac{1}{2} (10+t) y,\end{align*} while the lower right quadrilateral has area \begin{align*}A_2 &= \frac{1}{2} (20-t) y + \frac{1}{2} t (20 - x) \\ &= 10t -\frac{1}{2} t x +\frac{1}{2} (20-t) y.\end{align*} Imposing the condition that all three pieces of cake have the same area is mathematically equivalent to ensuring that $A_1 = A_2 = \frac{200}{3}$ which yields the following system of equations \begin{align*} (10-t) x + (10+t) y & = \frac{500-30t}{3} \\ -t x + (20-t) y & = \frac{400-60t}{3}.\end{align*} Solving for $x=x(t)$ and $y=y(t),$ we get $$P(t)=\begin{pmatrix} x(t)\\ y(t) \end{pmatrix} = \begin{pmatrix} 10-t & 10 + t \\ -t & 20-t \end{pmatrix}^{-1} \begin{pmatrix} \frac{500 -30t}{3} \\ \frac{400-60t}{3}\end{pmatrix} = \begin{pmatrix} \frac{15t^2-150t+1000}{t^2-10t +100} \\ \frac{15t^2-200t+250}{3(t^2-10t+100)} \end{pmatrix}.$$ Though the points won't exactly be correct, we can extend for $10 \leq t \leq 20$ by appealing to symmetry, from which we can define $x(t) = 20 - x(20-t)$ and $y(t)=y(20-t)$ whenever $10\leq t \leq 20.$

One solution (for $t=0$) has the center point $P(0)=(10, 20/3),$ with cuts hitting the perimeter at points $(0,0),$ $(20,0)$ and $(10,10).$

The parametric curve $P(t)=(x(t), y(t))$ encloses an area that can be approximated by the Riemann sum through horizontal slices for a given partition $t_0 = 0 \lt t_1 \lt \cdots \lt t_{N-1} \lt t_N = 10,$ as \begin{align*}A_N &= \sum_{i=1}^N \left(x(20 - t_{i-1}) - x(t_{i-1}) \right) \left(y(t_{i-1}) - y(t_i) \right) \\ &= \sum_{i=1}^N 2 \left(10 - x(t_{i-1}) \right) \frac{y(t_{i-1}) - y(t_i)}{t_i - t_{i-1}} \left( t_i - t_{i-1} \right).\end{align*} As $N \to \infty,$ we get that the area enclosed within the parametric curve of center points for the equitable area and perimeter cuts is given by \begin{align*}A &= \lim_{N \to \infty} A_N = -2 \int_0^{10} ( 10 - x(t) ) \frac{d}{dt} y(t) dt\\ &= \frac{1000}{3} \int_0^{10} \frac{(t^2 - 10t) (t^2 - 10t - 50)}{(t^2 - 10t + 100)^3} \,dt \\ &= \frac{1000}{3} \int_0^{10} \frac{t^4 - 20t^3 + 50t^2 + 500t}{(t^2 - 10t + 100)^3} \,dt \\ &= \frac{200}{27} \left[ \sqrt{3}\arctan \left( \frac{x-5}{5\sqrt{3}} \right) - \frac{30(x-5)^3}{(x^2 - 10x + 100)^2} \right]^{x=10}_{x=0} \\ &= \frac{400}{27} \left( \sqrt{3} \arctan\left(\frac{1}{\sqrt{3}}\right) - \frac{3}{8} \right) = \frac{50 \left( 4 \sqrt{3} \pi - 9 \right)}{81}\\ &\approx 7.879995... \,\, \text{in}^2.\end{align*}

Monday, February 26, 2024

I come to bury the Niners, not to praise them

Football is complicated, so let’s assume a simplified scoring model. Every time your team is on offense, suppose there’s a 1-in-3 chance they score a touchdown (which we’ll say is worth a total of 7 points, as we won’t bother with 2-point conversions here), a 1-in-3 chance they score a field goal (worth 3 points), and a 1-in-3 chance they don’t score any points (i.e., they punt or turn the ball over on downs). After any of these three things happens, your team will then be on defense and the other team will have the same scoring probabilities.

Now, here’s how overtime will work: Your team is on offense first. No matter how many points your team does or does not score, the other team then gets a chance at offense. If the game is still tied beyond this point, the teams will continue alternating between offense and defense. Whichever team scores next wins immediately. Again, your team is on offense first. What is your team’s probability of winning?

In this first model, each team has a probability $p_0$ of scoring no points, $p_3$ of scoring 3 points, and $p_7$ of scoring 7 points, with $p_0 + p_3 + p_7 = 1.$ Though, I suppose, you don't hope to get there, let's first analyze what happens if you end up getting to sudden death.

The probability of you winning in sudden death in your first possession of sudden death is $p_3 + p_7 = 1-p_0.$ Of course the only way that you could get to a second possession in sudden death is to first score nothing (with probability $p_0$) and have you opponent also score nothing (with probability $p_0$), and then to score with probability $1-p_0$. That is, the probability of scoring in sudden death on your second possession is $p_0^2 (1-p_0).$ Similarly, we can reason that the probability of winning on your $k$th possession in sudden death must by $(k-1)$ rounds of both teams not scoring, then you scoring in the $k$th possession, for a probability of $p_0^{2(k-1)}(1-p_0).$ Adding this all up, the probability of you winning in sudden death conditional on making it to sudden death is $$p_{SD} = \mathbb{P} \{ W \mid SD \} = \sum_{k=1}^\infty p_0^{2(k-1)} (1-p_0) = \frac{1-p_0}{1-p_0^2} = \frac{1}{1+p_0}.$$

If your first drive ends in scoring $7$, then there are two outcomes based on your opponent's outcomes, either (a) your opponent scores less than $7$, with probability $p_0 + p_3$, and you win; or (b) you enter sudden death, with probability $p_7$. So the probability of winning conditional on scoring a TD in your first drive is $$\Pi_7 = \mathbb{P} \{ W \mid 7 \} = p_0 + p_3 + p_7 p_{SD} = p_0 + p_3 + \frac{p_7}{1+p_0}.$$

If your first drive ends in scoring $3$, then there are three outcomes based on your opponent's outcomes, either (a) your opponent scores zero, with probability $p_0$, and you win; or (b) you enter sudden death, with probability $p_3$; or (c) your opponent scores 7, with probability $p_7,$ and you lose. So the probability of you winning conditional on scoring a FG in your first drive is $$\Pi_3 = \mathbb{P} \{ W \mid 3 \} = p_0 + p_3 p_{SD} = p_0 + \frac{p_3}{1 + p_0}.$$

If you don't score in your first drive, then you either (a) lose, with probability $p_3 + p_7$; or (b) enter into sudden death, with probability $p_0$. So the probability of you winning conditional on not scoring in your first drive is $$\Pi_0 = \mathbb{P} \{ W \mid 0 \} = p_0 p_{SD} = \frac{p_0}{1+p_0}.$$

Putting these all together, you have a total probability of winning if you go first of $$\Pi (p_0, p_3, p_7) = p_0 \Pi_0 + p_3 \Pi_3 + p_7 \Pi_7 = p_0p_3 + p_0p_7 + p_3p_7 + \frac{p_0^2 + p_3^2 + p_7^2}{1 + p_0}.$$ In this case, if, as in our toy model, we have $p_0 = p_3 = p_7 = \frac{1}{3}$, then the probability of winning if you go first is $$\Pi = \Pi(\frac{1}{3}, \frac{1}{3}, \frac{1}{3}) = \frac{1}{3^2} + \frac{1}{3^2} + \frac{1}{3^2} + \frac{\frac{1}{3^2} + \frac{1}{3^2} + \frac{1}{3^2}}{1 + \frac{1}{3}} = \frac{1}{3} + \frac{1}{4} = \frac{7}{12}.$$

Let's add this complexity to the model: When either team is on offense, they now have a choice. They can still opt for a strategy that results in 7 points, 3 points, or 0 points, each with a 1-in-3 chance. Alternatively, they can opt for a more aggressive strategy that results in 7 points or 0 points, each with a 1-in-2 chance.

Your team remains on offense first. Assuming both teams play to maximize their own chances of Super Bowl victory, now what is your team’s probability of winning?

So let's introduce $\tilde{p}_7,$ which is the probability of a TD under the aggressive offensive strategy, and $\tilde{p}_0 = 1 - \tilde{p}_7,$ which is the probability of not scoring under the aggressive offensive strategy. Let's first confirm that the probability of winning conditional on getting to sudden death in the more complicated model, $\tilde{p}_{SD},$ remains the same as before ( that is $\tilde{p}_{SD} = p_{SD})$), if and only if $p_3 + p_7 \geq \tilde{p}_7.$ If the parameters are such that rather $\tilde{p}_7 \gt p_3 + p_7,$ then we have $\tilde{p}_{SD} = \frac{1}{1+\tilde{p}_0},$ that is, $$\tilde{p}_{SD} = \frac{1}{1 + \min \{ p_0, \tilde{p}_0 \} }.$$

So let's now go through the various cases. If you score a TD in your first drive, then your opponent will win with probability $\tilde{p}_7 ( 1 - \tilde{p}_{SD} )$ and lose with probability $\tilde{p}_0 + \tilde{p}_7\tilde{p}_{SD}$ when he pursues the aggressive strategy. If he goes with the standard strategy, he will win with probability $p_7 (1 - \tilde{p}_{SD})$ and lose with probability $p_0 + p_3 + p_7 \tilde{p}_{SD}.$ So since your opponent will chose his own maximal winning probability that is equivalent to your minimal winning probability, so your probability of winning if you score a TD in your first drive if $$\tilde{\Pi}_7 = \min \{ \tilde{p}_0 + \tilde{p}_7 \tilde{p}_{SD}, p_0 + p_3 + p_7 \tilde{p}_{SD} \} = \frac{1 + \min\{\tilde{p}_0, 1-p_7\} \min \{p_0, \tilde{p}_0\}}{1 + \min \{ p_0, \tilde{p}_0 \}}.$$

If you score a FG in your first drive, then your opponent will have a $\tilde{p}_7$ chance of winning and $\tilde{p}_0$ chance of losing in the aggressive strategy. On the other hand, if using the standard strategy, your opponent will have a $p_7 + p_3 ( 1 - \tilde{p}_{SD} )$ probability of winning and a $p_0 + p_3 \tilde{p}_{SD}$ chance of losing. Thus, if you score a FG in your first drive, your probability of winning is $$\tilde{\Pi}_3 = \min \{\tilde{p}_0, p_0 + p_3\tilde{p}_{SD}\} = \min \left\{ \tilde{p}_0, \frac{1 - p_7 + p_0 \min \{p_0, \tilde{p}_0\}}{1 + \min \{p_0, \tilde{p}_0\}} \right\}.$$

If you do not score in your first drive, then your opponent will have a $p_3 + p_7 + p_0 (1 - \tilde{p}_{SD})$ probability of winning in a $p_0 \tilde{p}_{SD}$ probability of losing in the standard offense strategy. On the other hand, your opponent will have a $\tilde{p}_7 + \tilde{p}_0 (1 - \tilde{p}_{SD}) = 1 - \tilde{p}_0 \tilde{p}_{SD}$ probability of winning and $\tilde{p}_0 \tilde{p}_{SD}$ probability of losing in the aggressive strategy. So, if you don't score in your first drive your win probability is $$\tilde{\Pi}_0 = \min \{ p_0 \tilde{p}_{SD}, \tilde{p}_0 \tilde{p}_{SD} \} = \min \{p_0, \tilde{p}_0\} \tilde{p}_{SD} = \frac{\min \{p_0, \tilde{p}_0\}}{1 + \min \{ p_0, \tilde{p}_0 \} }.$$

So the total probability of winning is $$\tilde{\Pi} = \tilde{\Pi}(p_0, p_3, p_7, \tilde{p}_0, \tilde{p}_7) = \max \{ \tilde{p}_7 \tilde{\Pi}_7 + \tilde{p}_0 \tilde{\Pi}_7, p_7 \tilde{\Pi}_7 + p_3 \tilde{\Pi}_3 + p_0 \tilde{\Pi}_0 \}.$$ Given our parameters where $p_0 = p_3 = p_7 = \frac{1}{3}$ and $\tilde{p}_0 = \tilde{p}_7 = \frac{1}{2},$ the probability of winning when you go first in the updated model is \begin{align*} \tilde{\Pi}_0 &= \frac{ \min\{ \frac{1}{3}, \frac{1}{2} \} }{ 1 + \min \{ \frac{1}{3}, \frac{1}{2} \} } &= \frac{1}{4} \\ \tilde{\Pi}_3 &= \min \left\{ \frac{1}{2}, \frac{ 1- \frac{1}{3} + \frac{1}{3} \min \{ \frac{1}{3}, \frac{1}{2} \} }{ 1 + \min \{ \frac{1}{3}, \frac{1}{2} \} } \right\} &= \frac{1}{2} \\ \tilde{\Pi}_7 &= \frac{ 1 + \frac{1}{2} \min \{ \frac{1}{3}, \frac{1}{2} \} }{1 + \min \{ \frac{1}{3}, \frac{1}{2} \} } &= \frac{7}{8}\end{align*} In this case, the probability $$\tilde{\Pi} = \max \{ \frac{1}{2} \frac{7}{8} + \frac{1}{2} \frac{1}{4}, \frac{1}{3} \frac{7}{8} + \frac{1}{3} \frac{1}{2} + \frac{1}{3} \frac{1}{4} \} = \max \{ \frac{9}{16}, \frac{13}{24} \} = \frac{9}{16}.$$

Altogether this was not the dunking on the Niners and their decision that I hoped it would be, but luckily, whether the decision was correct or not, the Niners lost. That, in the end, is all that really matters!!!

Monday, February 5, 2024

Many, many, many to one function

For any positive, base-$10$ integer $N$, define $f(N)$ as the number of times you have to add up its digits until you get a one-digit number. For example, $f(23) = 1$ because $2+3 = 5$, a one-digit number. Meanwhile, $f(888) = 2,$ since $8+8+8 = 24,$ a two-digit number, and then adding up those digits gives you $2+4 = 6,$ a one-digit number. Find the smallest whole number $N$ such that $f(N) = 4.$

Clearly $\min f^{-1}(\{1\}) = 10,$ so we must figure out what the smallest integer whose base-$10$ digits sum to $10.$ In this case, we can guess and peck, and arrive at $19$. It becomes slightly harder to figure out the smallest integer whose base-$10$ digits sum to $19.$ Certainly there are no two digit numbers that sum to 19, since the maximum sum of base-$10$ digits of any two digit number is $18$. So let's look for three digit numbers $N = 100a + 10b + c$ where $a + b + c = 19,$ $a \in \{1, 2, \dots, 9\}$ and $b, c \in \{0, 1, \dots, 9\}.$ Obviously the minimal number involves $a = 1,$ where then $b=c=9.$

So we have $f(199) = 3.$ However, we want to now figure out what is the smallest integer whose base-$10$ digits sum to $199,$ since this will give us $\min f^{-1}(\{4\}).$ Since any $22$ digit number will sum to no more than $198,$ we should look for a $23$ digit number. In particular, if the first digit is a $1$ and it is followed by twenty-two $9$'s, then we would get $199$ as the sum of the digits. So, $N = 19,999,999,999,999,999,999,999$ is the smallest integer with $f(N) = 4.$

Let's enumerate the first $10,000$ values of the function $f.$ We can see that $f(N) = 0$ for $N \in \{1, 2, \dots, 9\}.$ As we saw before, $f(N) = 1$ for $N = 10, 11, dots, 18$ and then $f(19) = 2.$ Similarly, $f(N) = 1$ for $N = 20, \dots, 27$ and then $f(N) = 2$ for $N = 28$ and $N=29.$ Since, the maximum sum of the digits for of any integer $N \leq 10,000$ is $36,$ if all we wanted to do is determine which numbers in the first $10,000$ have value $f(N) = 3,$ we therefore only need to worry about numbers $N$ whose digits sum to either $19,$ $28$ or $29.$

We have already seen that, e.g., $199$ satisfies $f(199) = 3.$ By cleverly adding $90$ and $99,$ both of which preserve the total sum of digits provided that the $1000$'s digit remains unchanged, that there are $44$ other three digit numbers $N$ with $f(N) = 3,$ namely $289,$ $298,$ $379,$ $388,$ $398,$ $469,$ $478,$ $487,$ $496,$ $559,$ $568,$ $577,$ $586,$ $595,$ $649,$ $658,$ $667,$ $676,$ $685,$ $694,$ $739,$ $748,$ $757,$ $766,$ $775,$ $784,$ $793,$ $829,$ $838,$ $847,$ $856,$ $865,$ $874,$ $883,$ $892,$ $919,$ $928,$ $937,$ $946,$ $955,$ $964,$ $973,$ $982,$ and $991.$ We can continue adding other cleverly conjured addends (e.g., $900$) that preserve the sum of digits, or just let some even smarter computer run through all of the numbers for us. In the end, we get a total of $945$ integers $N$ with $1\leq N \leq 10,000$ and $f(N)=3$.

Monday, January 29, 2024

One square makes you faster, one square makes you slow...

A very tiny Alice (not to be confused with the Alice from last week) is racing across a 2-by-2 chessboard, as shown below, where each smaller square has a side length of 1 cm. Alice starts at the bottom-left corner of the bottom-left black square and is trying to reach the top-right corner of the top-right black square.

There’s just one catch. Alice moves faster on the white squares than she does on the black squares. Her speed on the white squares is 1 cm per minute (again, she’s very small), while her speed on the black squares is 0.9 cm per minute. What’s the least amount of time it will take her to reach the finish?

Since within each square, Alice's speed is constant, she will travel in straight lines within each square making a piecewise straight path from the lower left corner, at $(0,0)$, to upper right corners, at $(2,2)$. Let's say, based on the augmented picture below, that Alice first cuts a straight line for the point $(1,h)$ through the dark square, then heads to the point $(2-k, 1),$ before finishing at $(2,2),$ for some $0 \leq h, k \leq 1.$

The time elapsed in minutes by Alice for this path is $$T(h,k) = \frac{10}{9} \left( \sqrt{1 + h^2} + \sqrt{1 + k^2} \right) + \sqrt{ (1-h)^2 + (1-k)^2 }.$$ Taking the the gradient of the time elapsed function gives $$\nabla T = \begin{pmatrix} \frac{10h}{9\sqrt{1+h^2}} - \frac{1-h}{\sqrt{(1-h)^2 + (1-k)^2}} \\ \frac{10k}{9\sqrt{1+k^2}} - \frac{1-k}{\sqrt{(1-h)^2 + (1-k)^2}} \end{pmatrix}.$$ Setting the partial derivative with respect to $h$ to zero, we get $$\frac{10h}{9\sqrt{1+h^2}} = \frac{1-h}{\sqrt{(1-h)^2 + (1-k)^2}}.$$ Setting the partial derivative with respect to $k$ to zero, we get $$\frac{10k}{9\sqrt{1+k^2}} = \frac{1-k}{\sqrt{(1-h)^2 + (1-k)^2}}.$$ Combining these, we see that this would imply that $$\frac{h}{(1-h)\sqrt{1+h^2}} = \frac{k}{(1-k)\sqrt{1+k^2}},$$ which since $f(x) = \frac{x}{(1-x)\sqrt{1+x^2}}$ is monotonically increasing for $x \geq 0$ implies that $h = k.$ In this case, we get that we must have $$\frac{10h}{9\sqrt{1+h^2}} = \frac{1-h}{\sqrt{(1-h)^2 + (1-h)^2}} = \frac{1}{\sqrt{2}},$$ or equivalently $$\frac{h}{\sqrt{1+h^2}} = \frac{9\sqrt{2}}{20}.$$ Squaring both sides and solving for $h$, we get $h^2 ( 1 - \frac{81}{200} ) = \frac{81}{200},$ which give an optimal value of $h^* = k^* = \frac{9}{\sqrt{119}}.$ Plugging back into the time elapsed, shows that Alice can get reach the finish optimally in \begin{align*}T^* &= T\left( \frac{9}{\sqrt{119}}, \frac{9}{\sqrt{119}} \right) \\ &= \frac{20}{9} \sqrt{ 1 + \frac{81}{119} } + \sqrt{ \left(1 - \frac{9}{\sqrt{119}}\right)^2 + \left(1 - \frac{9}{\sqrt{119}} \right)^2 } \\ &= \frac{200 \sqrt{2}}{9 \sqrt{119}} + \sqrt{2} \left( 1 - \frac{9}{\sqrt{119}} \right) = \frac{\sqrt{2}}{\sqrt{119}} \left( \frac{200}{9} - 9 + \sqrt{119} \right)\\ &= \sqrt{2} \left( 1 + \frac{\sqrt{119}}{9} \right) \approx 3.12835... \,\text{minutes}.\end{align*}

Expanding Alice's journey to go to the final position of $(8,8),$ we can rely on certain portions of the argument for the $(2,2)$ case, but there are certainly some additional complications. Here we will generically have 14 possible values $h_1, \dots, h_{14}$ as shown in the figure below, we can rely on the symmetry to reduce the number of variables by a factor of two (i.e., $h_1 = h_{14}$, $h_2 = h_{13}$, $\dots$, $h_7 = h_8$).

In this case, we find that the time elapsed by Alice in minutes is \begin{align*}\tilde{T}(h_1, \dots, h_7) &= \frac{20}{9} \left( \sqrt{1+h_1^2} + \sum_{i=1}^3 \sqrt{h_{2i}^2 + h_{2i+1}^2} \right) \\ &\quad\quad+ 2\sqrt{(1-h_1)^2 + (1-h_2)^2} + 2\sqrt{(1-h_3)^2 + (1-h_4)^2}\\ &\quad\quad\quad + 2\sqrt{(1-h_5)^2 + (1-h_6)^2} + \sqrt{2} (1 - h_7).\end{align*}

In this case we can take the gradient of $\tilde{T}$ and get $$\nabla \tilde{T} (h) = \begin{pmatrix} \frac{20h_1}{9 \sqrt{1+h_1^2} } - \frac{2(1-h_1)}{\sqrt{ (1-h_1)^2 + (1-h_2)^2}} \\ \frac{20h_2}{9 \sqrt{h_2^2 + h_3^2} } - \frac{2(1-h_2)}{\sqrt{(1-h_1)^2 + (1-h_2)^2}} \\ \frac{20h_3}{9 \sqrt{h_2^2 + h_3^2} } - \frac{2(1-h_3)}{\sqrt{ (1-h_3)^2 + (1-h_4)^2}} \\ \frac{20h_4}{9 \sqrt{h_4^2 + h_5^2} } - \frac{ 2(1-h_4)}{\sqrt{ (1-h_3)^2 + (1-h_4)^2} } \\ \frac{20h_5}{9 \sqrt{h_4^2 + h_5^2} } - \frac{2 (1-h_5)}{\sqrt{(1-h_5)^2 + (1-h_6)^2}} \\ \frac{20h_6}{9 \sqrt{h_6^2 + h_7^2} } - \frac{ 2 (1-h_6) }{ \sqrt{ (1-h_5)^2 + (1-h_6)^2 } } \\ \frac{20h_7}{9 \sqrt{h_6^2 + h_7^2} } - \sqrt{2} \end{pmatrix}.$$ Let's first assume that there is some solution $\hat{h}$ in the interior of $[0,1]^7,$ where $\tilde{T}$ is infinitely differentiable. If we set the gradient to zero and solve for the last equation, we get that $$\frac{h_7^2}{h_6^2 + h_7^2} = \frac{81}{200},$$ which implies that $$\frac{h_6^2}{h_6^2 + h_7^2} = \frac{119}{200}.$$ Plugging this back into the second to last coordinate, we get that $$\frac{(1-h_6)^2}{(1-h_5)^2 + (1-h_6)^2} = \frac{1}{4} \frac{400}{81} \frac{119}{200} = \frac{119}{162},$$ which in turn implies that $$\frac{(1-h_5)^2}{(1-h_5)^2 + (1-h_6)^2} = \frac{43}{162}.$$ Plugging this into the third to last coordinate, we get that $$\frac{h_5^2}{h_4^2 + h_5^2} = \frac{81}{400} \cdot 4 \cdot \frac{43}{162} = \frac{43}{200},$$ which implies that $$\frac{h_4^2}{h_4^2 + h_5^2} = \frac{157}{200}.$$ Plugging this into the next coordinate, we get that $$\frac{(1-h_4)^2}{(1-h_3)^2 + (1-h_4)^2} = \frac{1}{4} \frac{400}{81} \frac{157}{200} = \frac{157}{162},$$ which implies that $$\frac{(1-h_3)^2}{(1-h_3)^2 + (1-h_4)^2} = \frac{5}{162}.$$ Continuing onward, this implies that $$\frac{h_3^2}{h_2^2 + h_3^2} = \frac{81}{400} \cdot 4 \cdot \frac{5}{162} = \frac{1}{40},$$ which in turn means that $$\frac{h_2^2}{h^2_2 + h^2_3} = \frac{39}{40}.$$ Plugging this value into the second coordinate and solving gives $$\frac{(1-h_2)^2}{(1-h_1)^2 + (1-h_2)^2} = \frac{1}{4} \frac{400}{81} \frac{39}{40} = \frac{65}{54};$$ however, this is a contradiction since for any $a, b \in \mathbb{R},$ $$\frac{a^2}{a^2 + b^2} \leq 1.$$ Therefore, there must not be some solution in the interior of $[0,1]^7.$

Instead, we must have solutions with some variables on the endpoints of $\{0, 1\}.$ While the contradiction above was arrived at by initially setting $h_7$ to something nonzero, we will arrive at similar contradictions unless we have $h_4 = h_5 = h_6 = h_7 = 0,$ since if let's say that $h_4 > 0 = h_5,$ then since the normal cone of $[0,1]^7$ at $h$ is given by $$\mathcal{N}_{[0,1]^7}(h) = \left\{ y \in \mathbb{R}^7_{-} \mid y_i h_i = 0 \right\}$$ in order for $h$ to be an optimizer of $\tilde{T}$ on $[0,1]^7$ we would need to have $$\frac{\partial}{\partial h_5} \tilde{T} = \frac{20}{9} - \frac{2 (1-h_4)}{\sqrt{(1-h_3)^2 + (1-h_4)^2} = 0,$$ which again since $$0 \leq \frac{1-h_4}{\sqrt{(1-h_3)^2 + (1-h_4)^2} } \leq 1$$ for all values of $h_3, h_4 \in [0,1]$ we will be hard pressed to solve. So let's then reduce the problem to optimizing the further reduced function \begin{align*}\check{T} (h_1, h_2, h_3) &= \tilde{T} (h_1, h_2, h_3, 0, 0, 0, 0)\\ &= \frac{20}{9} \left( \sqrt{1 + h_1^2} + \sqrt{h_2^2 + h_3^2} \right)\\ &\quad\quad + \sqrt{ (1-h_1)^2 + (1-h_2)^2 } + \sqrt{ 1 + (1-h_3)^2 } + 3 \sqrt{2}\end{align*} over $[0,1]^3.$

Here again, we have the reduced and slightly modified gradient $$\nabla \check{T} = \begin{pmatrix} \frac{20h_1}{9 \sqrt{1+h_1^2} } - \frac{2(1-h_1)}{\sqrt{ (1-h_1)^2 + (1-h_2)^2}} \\ \frac{20h_2}{9 \sqrt{h_2^2 + h_3^2} } - \frac{2(1-h_2)}{\sqrt{(1-h_1)^2 + (1-h_2)^2}} \\ \frac{20h_3}{9 \sqrt{h_2^2 + h_3^2} } - \frac{2(1-h_3)}{\sqrt{ 1 + (1-h_3)^2}}\end{pmatrix}.$$ Since this still yields some gnarly system of quadratics, at this point, though you can also just give up and program it, finding $\hat{h} = (0.485699\dots, 0.0737739\dots, 0.057801\dots)$ which yields an optimal value of $$\check{T}^* = \tilde{T}^* = 11.78815\dots$$ minutes for Alice to get to $(8,8)$.

Sunday, January 21, 2024

The Oldest Sister's Burden

Three siblings are at a playground: Alice, Bob, and Carey. Alice, the oldest, gets a call from their dad \emdash their pancake dinner is ready! But they won’t get to eat until all three kids are home.

They each walk home at a different constant speed. Alice can walk home in 10 minutes, Bob can do it in 20, and Carey in 30. Fortunately, any of the kids can carry any of the others on their back without reducing their own walking speed. (However, none of them can carry a kid who is, in turn, carrying another kid.) Assume that they can pick someone up, set someone down, and change direction instantaneously.

What is the fastest they can all get home?

Clearly Alice, the oldest sister will have to do some amount of carrying, else everyone will be waiting for Carey to get home in 30 minutes. If Bob is never carried, then the best possible dinner time is 20 minutes after their dad's call. To do better, let's envision a scheme where indefatiguable Alice first carries one sibling for $t$ minutes, then drops that sibling and reverses course and travels away from home to meet up with the other sibling, then carries that second sibling the rest of the way home.

The time, let's say $t_1 = t_1(t, v_2),$ it will take Alice to travel away from home until she meets up with the other sibiling will be a function of the chosen first time period $t$ and the speed of the second sibling, $v_2$. In particular, if Alice and the second sibling were both traveling for $t$ minutes, then given the differential in their speeds, they would be a distance of $\frac{t}{10} - tv_2$ apart (assuming distance to home is the unit length here). In this case, in order for both of them to make up that distance at their relative combined speed of $v_2 + \frac{1}{10},$ we have $$t_1 = t\frac{\frac{1}{10} - v_2}{\frac{1}{10}+ v_2} = t \frac{1-10v_2}{1+10v_2}.$$ Additionally of note, Alice and her second siblings meeting occurs $$d = d(t, v_2) = (t + t_1) v_2 = t v_2 \left( 1 + \frac{1 - 10v_2}{1 + 10v_2} \right) = \frac{ 2t v_2 }{1 + 10v_2}$$ home lengths away from the playground. So in order for Alice and the second sibling to arrive home, it will take another, let's say $$t_2 = t_2(t, v_2) = \frac{1 - d(t,v_2)}{0.1} = 10 - 10d = 10 - \frac{20tv_2}{1 + 10v_2}$$ minutes. So Alice and one sibling will arrive at \begin{align*}T_A = T_A(t,v_2) &= t + t_1(t, v_2) + t_2(t, v_2) \\ &= t + t \frac{1 - 10v_2}{1 + 10v_2} + 10 - \frac{20tv_2}{1+10v_2} \\ &= 10 + \frac{ t(1 + 10v_2) + t(1-10v_2) - 20 t v_2) }{1 + 10v_2} \\ &= 10 + \frac{ 2t - 20t v_2}{1 + 10v_2} = 10 + 2t \frac{1-10v_2}{1+10v_2}\end{align*} minutes.

Meanwhile, the first sibling that Alice dropped off after $t$ minutes has been trudging home under their own power at a uniform rate of $v_1$ and will arrive home at $$T_1 = T_1(t, v_1) = t + \frac{1 - \frac{t}{10}}{v_1} = \frac{1}{v_1} - t\frac{1 - 10v_1}{10 v_1}.$$ So the time when all of the siblings are safely home and devouring pancakes for dinner is \begin{align*}T = T(t, v_1, v_2) &= \max \{ T_A(t, v_2), T_1(t, v_1) \} \\ &= \max \left\{ 10 + 2t \frac{1 - 10v_2}{1 + 10v_2}, \frac{1}{v_1} - t \frac{1-10v_1}{10v_1} \right\} \end{align*} So in particular, if Alice first picks up Bob and then Carey, we have $$T_{B,C} = T_{B,C} (t) = T\left(t, \frac{1}{20}, \frac{1}{30}\right) = \max \{ 10 + t, 20 - t \},$$ while if Alice first picks up Carey and then Bob, we have $$T_{C,B} = T_{C,B} (t) = T\left(t, \frac{1}{30}, \frac{1}{20}\right) = \max \left\{10 + \frac{2}{3}t, 30 -2t \right\}.$$ The optimal value of $T_{B,C}$ is $$T_{B,C}^* = \min_{t \in [0,10]} T_{B,C} (t) = 15 \,\text{minutes},$$ which occurs when $t^* = 5$ minutes; whereas, the optimal value of $T_{C,B}$ is $$T_{C,B}^* = \min_{t \in [0,10]} T_{C,B} (t) = 17.5 \, \text{minutes},$$ which occurs when $t^* = 6.5$ minutes. So between the two cases of carrying Bob first or carrying Carey first, the children will be eating pancakes sooner if Alice carries Bob first.

We can safely exclude the cases of either Bob carrying Carey at first, or Alice having more than one session of carrying any individual sibling, since each of these cases would lead to Carey, the slowest of the bunch, having a longer average speed home and thus delaying pancake festivities. Therefore, the fastest that Alice, Bob and Carey can all get home is in 15 minutes, where Alice carries Bob for 5 minutes, then sends him home, goes back to meet Carey and upon meeting Alice carries Carey the rest of the way home.

Monday, January 15, 2024

Dice Dungeon

Two people are sitting at a table together, each with their own bag of six “DnD dice”: a d4, a d6, a d8, a d10, a d12, and a d20. Both people randomly pick one die from their respective bags and then roll them at the same time. For example, suppose the two dice selected are a d4 and a d12. The players roll them, and let’s further suppose that both rolls come up as 3. What luck!

What’s the probability of something like this happening? That is, what is the probability that both players roll the same number, whether or not they happened to pick the same kind of die?

There are twenty possible outcomes $1, 2, \dots, 20$, however, since for instance, the probability that a d4 die rolls 17 is nil, we have a non-uniform distribution of outcomes. All outcomes less than or equal to $4$ are always possible no matter which die is selected, so the probability is $$p_i = \frac{1}{6} \left( \frac{1}{4} + \frac{1}{6} + \frac{1}{8} + \frac{1}{10} + \frac{1}{12} + \frac{1}{20} \right) = \frac{93}{720}, \,\, i = 1, 2, 3, 4.$$ The conditional probability of getting i \in \{5,6\} given that the d4 die was selected is zero, so we have $$p_i = \frac{1}{6} \left( 0 + \frac{1}{6} + \frac{1}{8} + \frac{1}{10} + \frac{1}{12} + \frac{1}{20} \right) = \frac{63}{720}, \,\, i = 5,6.$$ Doing similar manipulations for other outcomes gives $$p_i = \begin{cases} \frac{93}{720}, &\text{for $i = 1, 2, 3, 4$}\\ \frac{63}{720}, &\text{for $i = 5,6$;}\\ \frac{43}{720}, &\text{for $i = 7,8$;}\\ \frac{28}{720}, &\text{for $i = 9,10$;}\\ \frac{16}{720}, &\text{for $i = 11,12$;}\\ \frac{6}{720}, &\text{for $i = 13, 14, 15, 16, 17, 18, 19, 20$.}\end{cases}$$

Let the roll person 1 be $X,$ with probability distribution given by $\mathbb{P} \{ X = i \} = p_i.$ Similarly let the roll of person 2 be $Y,$ which has the i.i.d. distribution. Then the probability that both rolls are the same, i.e., $X=Y,$ is given by \begin{align*}\mathbb{P} \{ X = Y \} &= \sum_{i=1}^{20} \mathbb{P} \{ X = Y = i \} \\ &= \sum_{i=1}^{20} \mathbb{P} \{X=i\} \mathbb{P} \{Y = i\}\\ &= \sum_{i=1}^{20} p_i^2 \\ &= \frac{1}{720^2} \left( 4 \cdot 93^2 + 2 \cdot 63^2 + 2 \cdot 43^2 + 2 \cdot 28^2 + 2 \cdot 16^2 + 8 \cdot 6^2 \right) \\ &= \frac{48600}{518400} = \frac{3}{32} = 9.375\%.\end{align*}

If we went further and added a third person who has a bag of DnD dice. Again, all three randomly pick one die from their respective bags and roll them at the same time. For example, suppose the three dice selected are a d4, a d20, and a d12. The players roll them, and let’s further suppose that the d4 comes out as 4, the d20 comes out as 13, and the d12 comes out as 4. In this case, there are two distinct numbers (4 and 13) among the three rolls.

On average, how many distinct numbers would you expect to see among the three rolls?

Well the hard part of establishing the distribution is done, so let's assume $X$, $Y$ and now $Z$ are all i.i.d. with $\mathbb{P}\{X = i\} = \mathbb{P}\{Y=i\} = \mathbb{P}\{Z=i\} = p_i, i = 1, 2, \dots, 20.$ Let $N$ be the number of distinct rolls. I'm lazy so I'm going to leave $N=3$ alone and instead tackle $N=1$ and $N=2.$ The probability that $X=Y=Z$ and hence $N = i$ is by extension of the previous problem $$\mathbb{P} \{N=1\} = \sum_{i=1}^{20} p_i^3 = \frac{3930360}{373248000} = \frac{32753}{3110400} \approx 1.05302.....\%$$

For $N=2,$ we have a modicum of work. As we saw above if $X=Y$ then this would be represented by $p_i^2,$ but then in this case of $N = 2,$ we must have $Z \ne X=Y,$ which has probability of $(1-p_i).$ Furthermore, since the order of $X, Y, Z$ doesn't matter, there are 3 possible ways to get two rolls of $i$ and one roll of anything but $i.$ So we have $$\mathbb{P} \{ N=2\} = 3 \sum_{i=1}^{20} p_i^2 (1-p_i) = \frac{93184920}{373248000} = \frac{776541}{3110400} \approx 24.96595....\%$$

The only thing left to do is compute the expectation, \begin{align*}\mathbb{E} [N] &= 1 \cdot \mathbb{P} \{ N=1\} + 2 \cdot \mathbb{P} \{N=2\} + 3 \cdot \left( 1- \mathbb{P}\{N=1\} - \mathbb{P} \{N=2\} \right)\\ &= 3 - 2\mathbb{P} \{N=1\} -\mathbb{P}\{N=2\}.\end{align*} So the expected number of unique numbers among the three rolls is \begin{align*}\mathbb{E}[N] &= 3 - 2 \cdot \frac{32753}{3110400} - \frac{776541}{3110400} \\ &= \frac{9006847}{3110400} \approx 2.89571984\end{align*}