Monday, December 25, 2023

Voluminous rectangular prisms

There are several rectangular prisms with integer edge lengths that have an internal diagonal of length $2024.$ What is the greatest volume among these prisms?

Let's say we have a retangular prism with length $\ell,$ width $w,$ and height $h.$ The volume is $V = \ell w h$ while the length of the internal diagonal is $L = \sqrt{\ell^2 + w^2 + h^2}.$ In this case, we then need to looks for all Pythagorean quadruples $a^2 + b^2 + c^2 = d^2$ that have $d=2024.$ While we certainly could use primitive Pythagorean quadruples for the odd divisors of $2024$ (namely, $11$, $23,$ and $253$), we might as well just brute force the entire thing and do a dumb search: In a series of nested loops, we can loop through $a = 1, \dots, 2024,$ $b = a, a+1, \dots, 2024,$ and $c = b, b+1, \dots, 2024$ and print out the triple $(a, b, c)$ any time that $a^2 +b^2 + c^2 = 2024^2.$ This yields the following forty-one quadruples:

\begin{align*} 24^2 + 640^2 + 1920^2 &= 2024^2 \\ 24^2 + 1152^2 + 1664^2 &= 2024^2 \\ 64^2 + 168^2 + 2016^2 &= 2024^2 \\ 64^2 + 1344^2 + 1512^2 &= 2024^2 \\ 96^2 + 152^2 + 2016^2 &= 2024^2 \\ 96^2 + 872^2 + 1824^2 &= 2024^2 \\ 96^2 + 936^2 + 1792^2 &= 2024^2 \\ 96^2 + 1088^2 + 1704^2 &= 2024^2 \\ 152^2 + 864^2 + 1824^2 &= 2024^2 \\ 168^2 + 1344^2 + 1504^2 &= 2024^2 \\ 192^2 + 856^2 + 1824^2 &= 2024^2 \\ 192^2 + 1304^2 + 1536^2 &= 2024^2 \\ 224^2 + 600^2 + 1920^2 &= 2024^2 \\ 224^2 + 672^2 + 1896^2 &= 2024^2 \\ 224^2 + 1176^2 + 1632^2 &= 2024^2 \\ 264^2 + 528^2 + 1936^2 &= 2024^2 \\ 264^2 + 1232^2 + 1584^2 &= 2024^2 \\ 280^2 + 576^2 + 1920^2 &= 2024^2 \\ 360^2 + 800^2 + 1824^2 &= 2024^2 \\ 360^2 + 1376^2 + 1440^2 &= 2024^2 \\ 368^2 + 1104^2 + 1656^2 &= 2024^2 \\ 424^2 + 480^2 + 1920^2 &= 2024^2 \\ 424^2 + 768^2 + 1824^2 &= 2024^2 \\ 424^2 + 1248^2 + 1536^2 &= 2024^2 \\ 480^2 + 576^2 + 1880^2 &= 2024^2 \\ 528^2 + 1144^2 + 1584^2 &= 2024^2 \\ 576^2 + 744^2 + 1792^2 &= 2024^2 \\ 576^2 + 928^2 + 1704^2 &= 2024^2 \\ 576^2 + 1216^2 + 1512^2 &= 2024^2 \\ 576^2 + 1368^2 + 1376^2 &= 2024^2 \\ 600^2 + 640^2 + 1824^2 &= 2024^2 \\ 672^2 + 936^2 + 1664^2 &= 2024^2 \\ 672^2 + 1176^2 + 1504^2 &= 2024^2 \\ 744^2 + 1088^2 + 1536^2 &= 2024^2 \\ 768^2 + 1304^2 + 1344^2 &= 2024^2 \\ 768^2 + 1304^2 + 1344^2 &= 2024^2 \\ 856^2 + 1248^2 + 1344^2 &= 2024^2 \\ 864^2 + 1216^2 + 1368^2 &= 2024^2 \\ 928^2 + 936^2 + 1536^2 &= 2024^2 \\ 936^2 + 1152^2 + 1376^2 &= 2024^2 \\ 1104^2 + 1104^2 + 1288^2 &= 2024^2 \end{align*}

The rectangular prism with integral edge lengths internal diagonal length of $2024$ with the largest volume is $1104 \times 1014 \times 1288$ which has volume $1,569,835,008.$ Note that this is not necessarily that far from the overall, non-integral solution of a cube with side length $2024 / \sqrt{3}$ which has volume $1,595,694,111.621353...$, which is only about $1.6\%$ larger than the volume of the integral rectangular prism, so not too shabby.

Monday, December 18, 2023

You've got be flipping kidding me!

Kyle and Julien are playing a game in which they each toss their own fair coins. On each turn of the game, both players flip their own coin once. If, at any point, Kyle’s most recent three flips are Tails, Tails, and Heads (i.e., TTH), then he wins. If, at any point, Julien’s most recent three flips are Tails, Tails, and Tails (i.e, TTT), then he wins.

However, both players can’t win at the same time. If Kyle gets TTH at the same time Julien gets TTT, then no one wins, and they continue flipping. They don’t start over completely or erase their history, mind you—they merely continue flipping, so that one of them could conceivably win in the next flip or two.

What is the probability that Kyle wins this game?

This game, like many coin flipping problems of its ilk, can be modeled as a Markov chain. There are two absorbing states, let's call them, $\textsf{WinJ}$ and $\textsf{WinK}$, and nine transient states, call them, $(i, j)$ where $i, j \in \{0, T, TT\},$ represent the state where Julien is in state $i$ and Kyle is in state $j.$ State $(0,0),$ which represents both the starting space and the case that both Julien and Kyle just flipped H and that Kyle's last three flips were not TTH, can transition to $(T,0)$, $(0,T)$, $(T,T)$ or itself, each with equal probability. On the other hand, we see that due to the tie breaker procedures, state $(TT, TT)$ can transition to $(0,0)$, $\textsf{WinJ}$, $\textsf{WinK}$ and $(TT,0),$ each with equal probability. We can similarly build up all of the other transitions Let's represent the probabilistic state of the system as $\pi = (p_\textsf{WinJ}, p_\textsf{WinK}, p_{(0,0)}, p_{(0,T)}, p_{(0,TT)}, p_{(T,0)}, p_{(T,T)}, p_{(T,TT)}, p_{(TT,0)}, p_{(TT,T)}, p_{(TT,TT)} ) \in [0,1]^{11},$ then the probability transition matrix can be represented as $$P = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0.25 & 0.25 & 0 & 0.25 & 0.25 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0.25 & 0 & 0.25 & 0.25 & 0 & 0.25 & 0 & 0 & 0 \\ 0 & 0.5 & 0.25 & 0 & 0 & 0.25 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0.25 & 0.25 & 0 & 0 & 0 & 0 & 0.25 & 0.25 & 0 \\ 0 & 0 & 0.25 & 0 & 0.25 & 0 & 0 & 0 & 0.25 & 0 & 0.25 \\ 0 & 0.5 & 0.25 & 0 & 0 & 0 & 0 & 0 & 0.25 & 0 & 0 \\ 0.5 & 0 & 0.25 & 0.25 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0.5 & 0 & 0.25 & 0 & 0.25 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0.25 & 0.25 & 0.25 & 0 & 0 & 0 & 0 & 0 & 0.25 & 0 & 0 \end{pmatrix}.$$ We can subdivide the transition matrix into the resolving states, $$R = \begin{pmatrix} 0 & 0 \\ 0 & 0 \\ 0 & 0.5 \\ 0 & 0 \\ 0 & 0 \\ 0 & 0.5 \\ 0.5 & 0 \\ 0.5 & 0 \\ 0.25 & 0.25 \end{pmatrix}$$ and the transitory states $$T = \begin{pmatrix} 0.25 & 0.25 & 0 & 0.25 & 0.25 & 0 & 0 & 0 & 0 \\ 0.25 & 0 & 0.25 & 0.25 & 0 & 0.25 & 0 & 0 & 0 \\ 0.25 & 0 & 0 & 0.25 & 0 & 0 & 0 & 0 & 0 \\ 0.25 & 0.25 & 0 & 0 & 0 & 0 & 0.25 & 0.25 & 0 \\ 0.25 & 0 & 0.25 & 0 & 0 & 0 & 0.25 & 0 & 0.25 \\ 0.25 & 0 & 0 & 0 & 0 & 0 & 0.25 & 0 & 0 \\ 0.25 & 0.25 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0.25 & 0 & 0.25 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0.25 & 0 & 0 & 0 & 0 & 0 & 0.25 & 0 & 0 \end{pmatrix}$$ such that we can represent the transition matrix $P$ in block form as $P = \begin{pmatrix} I & 0 \\ R & T \end{pmatrix}.$ If we start at particular state, say $\pi_0,$ then by the $n$th step, our probabilistic state is $$\pi_n = \pi_0 P^n = \pi_0 \begin{pmatrix} I & 0 \\ (I + T + T^2 + \dots + T^{n-1}) R & T^n \end{pmatrix}.$$ If we let $n \to \infty,$ then since $T^n \to 0$ and $I + T + T^2 + \dots + T^{n-1} \to (I - T)^{-1},$ we have that the ultimate transition matrix is $$\pi_\infty = \pi_0 \begin{pmatrix} I & 0 \\ (I - T)^{-1} R & 0 \end{pmatrix}.$$

Here, the probability that Kyle wins is given by the $p_\textsf{WinK}$ (2nd) entry in $\pi_\infty.$ Since we are starting at $\pi_0 = (0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0),$ and we are only concerned with $p_\textsf{WinK}$ we can instead of solving the entire matrix inverse of $I - T$ rather just solve the system of equations $$(I - T) x = R \begin{pmatrix} 0 \\ 1 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ 0.5 \\ 0 \\ 0 \\ 0.5 \\ 0 \\ 0 \\ 0.25 \end{pmatrix}$$ and then taking the first coordinate. Choosing your favorite matrix alegbra software, programming language or, due to certain foibles with which you are burdened, a bunch of loose leaf paper and loads of patience, you get to the probability that Kyle will win as $$p_\textsf{WinK} = \frac{36367}{74368} = 48.9014....\%$$

Monday, November 13, 2023

It's polygon pull weather

Your goal is to squeeze two non-overlapping quadrilaterals within a unit circle (i.e., a circle with radius 1). The quadrilaterals can share common edges, parts of edges, or vertices, but their interiors may not overlap. Their vertices may also lie on the circle’s circumference.

What is the greatest combined area these quadrilaterals can have?

When it comes to fitting shapes inside a circle, the best guess for largest possible area will be a regular polygon. So let's see what configurations we can come up with for two smushed together quadrilaterals. If we have two quadrilaterals that don't share any edges whatsoever, then we're not trying very hard since we could just expand one or the other quadrilateral until they do have a nonempty intersection and in turn get a larger total area. Similarly, if we have quadrilaterals that only intersect in a portion of an edge, then we can enlarge one or the other of the quadrilaterals until the entire edge is shared and get a larger total area. If the quadrilaterals only intersect in a single vertex then either one or the other can be orthogonally rotated such that the resulting quadrilaterals are all

OK, so now that we've covered that we should share entire edges, let's cover two cases: If we have two quadrilaterals that share two sides, then at most there could only be $4$ vertices along the circle. This configuration would have a maximum area obtained by a square inscribed in the circle, which has an area of $2.$ If instead, we have two quadrilaterals that share exactly one side, then at most there could be $6$ vertices along the circle. The area of a regular hexagon inscribed in a unit circle is $\frac{3\sqrt{3}}{2} = 2.59807...$ which is the largest total area of two non-overlapping quadrilaterals within a unit circle.

But what if we wanted to stick to only four vertices along the circle and define $Z$ as the following sum: the area of the (convex) quadrilateral formed by all four of these points plus the area of the largest triangle (by area) formed by any three of these points. Given that the four distinct points can be anywhere on the unit circle, what is the greatest possible value of $Z$?

Let's assume that the four vertices are numbered in say clockwise order, $z_1$, $z_2$, $z_3$, and $z_4$. Let the measure of the angle between the radii connecting $z_i$ and $z_{i+1}$ be $\alpha_i,$ for $i = 1, 2,$ and $3.$ For completeness, let the measure of the angle between the radii connecting $z_4$ and $z_1$ is $\alpha_4 = 2\pi - \alpha_1 - \alpha_2 - \alpha_3.$ In this case, the area of the quadrilateral is given by $$A_\square = \frac{1}{2} \sum_{i=1}^4 \sin \alpha_i.$$ Similarly, the area of the triangle formed by $z_1,$ $z_2$ and $z_3$ is $$A_\triangle = \frac{1}{2} \sin \alpha_1 + \frac{1}{2} \sin \alpha_2 - \frac{1}{2} \sin (\alpha_1 + \alpha_2).$$ Extending this to all of the triangles gives us the formula for \begin{align*}Z = Z(\alpha_1, \alpha_2, \alpha_3, \alpha_4) &= \frac{1}{2} \sum_{i=1}^4 \sin \alpha_i + \frac{1}{2} \max \left\{ \sin \alpha_1 + \sin \alpha_2 - \sin ( \alpha_1 + \alpha_2 ) ,\right.\\ &\quad\quad\quad \sin \alpha_2 + \sin \alpha_3 - \sin ( \alpha_2 + \alpha_3 ),\\ &\quad\quad\quad \sin \alpha_3 + \sin \alpha_4 - \sin ( \alpha_3 + \alpha_4 ),\\ &\quad\quad\quad \left.\sin \alpha_4 + \sin \alpha_1 - \sin ( \alpha_4 + \alpha_1 ) \right\}.\end{align*} Then all we need to do is optimize subject to $\alpha_1 + \alpha_2 + \alpha_3 + \alpha_4 = 2\pi.$ Without loss of generality, let's assume that the triangle between $z_1,$ $z_2$ and $z_3$ is (one of) the largest of the triangles, so that in some region of the optimal values of $\alpha_1, \alpha_2, \alpha_3, \alpha_4$ we have $$\tilde{Z} = \sin \alpha_1 + \sin \alpha_2 + \frac{1}{2} \sin \alpha_3 + \frac{1}{2} \sin \alpha_4 - \frac{1}{2} \sin ( \alpha_1 + \alpha_2 ).$$ In this case, we would have expect from the method of Lagrange multipliers that there is some $\lambda \in \mathbb{R}$ such that the following system of equations holds \begin{align*} \cos \alpha_1 - \frac{1}{2} \cos (\alpha_1 + \alpha_2) + \lambda &= 0 \\ \cos \alpha_2 - \frac{1}{2} \cos (\alpha_1 + \alpha_2) + \lambda &= 0\\ \frac{1}{2} \cos \alpha_3 + \lambda &= 0 \\ \frac{1}{2} \cos \alpha_4 + \lambda &= 0\end{align*}

From the last two equations, we can conclude that $\cos \alpha_3 = \cos \alpha_4,$ so since $\alpha_i \in [0,\pi],$ for $i = 1, 2, 3, 4$ we conclude that $\alpha_3 = \alpha_4.$ Similarly, from the first two equations, we can conclude that $\cos \alpha_1 = \cos \alpha_2,$ and that $\alpha_1 = \alpha_2.$ Therefore, we can reduce the Lagrange multiplier equations above, by setting $\eta = \alpha_1 = \alpha_2$ and $\eta = \alpha_3 = \alpha_4.$ In this case we have the following equations \begin{align*} \cos \zeta - \frac{1}{2} \cos 2\zeta + \lambda &= 0 \\ \frac{1}{2} \cos \eta + \lambda &= 0 \\ \zeta + \eta &= \pi\end{align*} Further reducing to a single variable we see that from the last equation $\eta = \pi - \zeta,$ and the second equation reveals $$\lambda = -\frac{1}{2} \cos \eta = - \frac{1}{2} \cos (\pi - \zeta) = \frac{1}{2} \cos \zeta,$$ so we a single equation $$ \frac{3}{2} \cos \zeta - \frac{1}{2} \cos 2\zeta = \frac{3}{2} \cos \zeta - \cos^2 \zeta + \frac{1}{2} = 0.$$ Solving this quadratic we get $\cos \zeta = \frac{3 - \sqrt{17}}{4},$ since the other root would be greater than $1,$ which in turn leads to $$\zeta = \cos^{-1} \frac{3 - \sqrt{17}}{4} \approx 1.85539928817...$$ From here, since $$\sin \zeta = \sqrt{ 1 - \cos^2 \zeta } = \sqrt{ \frac{3 \sqrt{17} - 5}{8} }$$ we get an optimal $Z$ of \begin{align*}\hat{Z} = Z( \zeta, \zeta, \pi - \zeta, \pi - \zeta ) &= 2\sin \zeta + \sin (\pi - \zeta) - \frac{1}{2} \sin 2\zeta \\&= 3 \sin \zeta - \sin \zeta \cos \zeta \\ &= (3 - \cos \zeta) \sin \zeta \\&= \left( 3 - \frac{3 - \sqrt{17}}{4} \right) \sqrt{ \frac{3 \sqrt{17} - 5}{8} } \\&= \frac{\sqrt{214 + 102 \sqrt{17}} }{8} \approx 3.14880129428....\end{align*}

Monday, September 25, 2023

Enumeration of triambuses? Rhombangles?

Earlier this month, I watched La Vuelta, one of the three grand tours of cycling (a trio that includes the Tour de France). I noticed the peloton—the main group of riders—took on an aerodynamic profile that sometimes looked like a triangle, sometimes looked like a rhombus, and sometimes looked somewhere in between.

For example, the figure below shows the four possible formations between a triangle and a rhombus when the peloton’s maximum width is four riders:

For certain numbers of riders, multiple formations like these are possible. In particular, there are two formations with 15 riders: a triangle that’s five riders wide at the base and an almost-rhombus that’s four riders wide in the middle, but missing the bottommost rider, as shown below.

After 15, what is the next smallest number of riders that similarly has two distinct formations between a triangle and a rhombus?

Taking a hint from the formations for $N=15$ riders, let's try to find the formula for all number of riders that have two formations between a triangle and a rhombus where one formation is a triangle and the other has one more row. Let's denote these numbers as $N_k^{(1)}.$ Let's start with a triangle with $n$ rows, then we could get one triangle of $n+k$ rows, and another formation by adding $k+1$ rows of descending length, from $n-1$ through $n-k-1.$ In this case, in the first formation, there are $\sum_{i=1}^k (n+i) = kn + \frac{k(k+1)}{2}$ riders added beyond the initial triangle. In the second formation, there are $\sum_{i=1}^{k+1} (n-i) = (k+1)n - \frac{(k+1)(k+2)}{2}$ additional riders. In this case we can then solve for $n$ in terms of $k$ to see that $$kn + \frac{k(k+1)}{2} = (k+1)n - \frac{(k+1)(k+2)}{2} \Rightarrow n = \frac{k(k+1)}{2} + \frac{(k+1)(k+2)}{2} = (k+1)^2.$$ Thus, for any $k \in \mathbb{N},$ $N_k^{(1)}$ is number of riders in a triangle with $(k+1)^2 + k$ rows, that is $$N_k^{(1)} = \frac{(k+1)(k+2)(k^2+3k+1)}{2}.$$

We can continue to define more configurations, e.g., let's say all number of riders that have two formations between a triangle and a rhombus where one formation is a triangle and the other has $\ell$ more rows, that is, $N^{(\ell)}_k.$ For the case of $\ell = 2,$ we would have $$\sum_{i=1}^k (n+i) = kn+\frac{k(k+1)}{2} = (k+2)n - \frac{(k+2)(k+3)}{2} = \sum_{i=1}^{k+2} (n-i),$$ which would imply that $$2n = \frac{k(k+1)}{2} + \frac{(k+2)(k+3)}{2} = k^2 + 3k + 3 = (k+1) (k+2) + 1;$$ however, since $(k+1)(k+2)$ is even, $(k+1) (k+2) + 1$ is always odd for all k, so there can be no solutions and there are no $k$ for which $N^{(2)}_k$ is defined. Luckily, all is not lost since as soon as we reach $\ell = 3,$ things start getting somewhat better. For $\ell = 3$, we have $$\sum_{i=1}^k (n+i) = kn+\frac{k(k+1)}{2} = (k+3)n - \frac{(k+3)(k+4)}{2} = \sum_{i=1}^{k+3} (n-i),$$ which would imply that $$3n = \frac{k(k+1)}{2} + \frac{(k+3)(k+4)}{2} = k^2 + 4k + 6 = (k+3)(k+1) + 3,$$ that is, $$n = \frac{(k+1)(k+3)}{3} + 1, \,\,\,\text{for $k \equiv 0, 2 \!\! \mod 3.$}$$ So since the total number of riders is the same as a triangle of $n+k$ rows, we have $$N^{(3)}_k = \frac{(k+1)(k+6)(k^2+7k+9)}{18},$$ whenever $k \equiv 0, 2 \mod \!\! 3.$ Similarly, we can find $$N_k^{(4)} = \frac{(k+2)(k+7)(k^2+9k+10)}{32},$$ whenever $k \equiv 1,2 \mod \!\! 4$ and $k \gt 2$ and $$N_k^{(5)} = \frac{(k^2+11k+15)(k^2+11k+20)}{100},$$ whenever $k \equiv 0, 4 \mod\!\!5$ and $k \gt 3.$

Though it is certainly possible that there might be others, I am somewhat confident that the next smallest number of riders with two or more formations is $N_2^{(3)} = 36.$ I am less confident, but will put it out there regardless, that $1275$ is the smallest number of riders that has three different formations, since we have both $N_9^{(3)} = N_{10}^{(4)} = 1275.$ In particular, the three formations for $1275$ riders are (a) a triangle of $50$ rows; (b) a triangle with $40$ rows, followed by $14$ rows of descending length; or (c) a triangle of $41$ rows, followed by $13$ rows of descending length.

For completeness, my working version of the sequence for number of riders that can form multiple triambuses or rhombangles or whatever we want to call them is: $$15, 36, 60, 66, 78, 95, 190, 210, 253, 325, 390, 406, 435, 518, 861, 903, 946, 1275, 1351, 1540, 1661, 2346, 2556, 2775, 3081, 3452, 3486, 4005, 4064, ....$$ However, more accurately, we can just throw on the working conditions, that it is the sequence of all numbers of riders that can form multiple triambuses where the overall number of rows in the different triambus formations differs by less than the index where I gave up, er, I mean less than $6$.

Sunday, September 10, 2023

Bobbin' and weavin'

A weaving loom set comes with a square with equally spaced hooks along each of its sides, as well as elastic bands that can be attached to the hooks.

Suppose a particular weaving loom has $N$ hooks on each side, evenly spaced from one corner to another (i.e., there are two hooks on the two corners and $N−2$ hooks between them). Let’s label the hooks along one side $A_1$ through $A_N$, the hooks on the next clockwise side $B_1$ through $B_N$ (with $A_N$ and $B_1$ denoting the same hook), the hooks on the third clockwise side $C_1$ through $C_N$, and the hooks on the final side $D_1$ through $D_N$.

Next, let’s use a whole bunch of elastic bands to connect hooks $A_1$ and $B_1$, $A_2$ and $B_2$, $A_3$ and $B_3$, and so on, up to $A_N$ and $B_N$. When $N = 100$, here’s what the loom looks like:

As $N$ increases, what is the shape of the curve formed by the edges of the bands?

Let's set up the framework, by assuming that the weaving loom, no matter the value of $N$, is the unit square $[0,1] \times [0,1].$ So that for instance $A_i = (0, \frac{N-i}{N-1})$ and $B_i = (\frac{i-1}{N-1}, 0),$ for $i = 1, \dots, N.$ The band connecting $A_i$ to $B_i$ can be represented by the line $$y = \frac{N-i}{N-1} \left(1 - \frac{N-1}{i-1} x\right) = \frac{N-i}{N-1} - \frac{N-i}{i-1} x.$$ Since we are primarily worried about the aggregate curve that is traced out by all of these lines, we really want to have $$f_N(x) = \max_{i = 2, \dots, N} \left\{ \frac{N-i}{N-1} - \frac{N-i}{i-1}x \right\}$$ which will eventually form a continuously differentiable function $f(x) = \lim_{N\to \infty} f_N(x).$

The interval on why the line from $A_i$ to $B_i$ will be maximal is $\left[ \frac{(i-1)(i-2)}{(N-1)^2}, \frac{i(i-1)}{(N-1)^2} \right]$ and the midpoint of this interval is $x_i = \left(\frac{i-1}{N-1}\right)^2.$ If we can find some convex $f$ such that $f_N(x_i) = f(x_i)$ for each $i = 2, \dots, N$ and $$\frac{d}{dx} f(x_i) = -\frac{N-i}{i-1},$$ for each $i = 2, \dots, N,$ then $f(x) = \lim_{N \to \infty} f_N(x)$ for all $x \in [0,1],$ since convex functions are the pointwise supremum of all affine minorants, up to and including their subdifferentials. So in particular, we see that $$-\frac{N-i}{i-1} = -\frac{N-1 - (i-1)}{i-1} = 1 - \frac{1}{\sqrt{x_i}},$$ for each $i = 2, \dots, N.$ Therefore, our best guess would be $$f(x) = f(0) + \int_0^x (1 - \frac{1}{\sqrt{t}}) dt = f(0) + x - 2\sqrt{x}.$$ Since the first band from $A_1$ to $B_1$ is along the $y$-axis, we should define $f(0) = 1,$ so that the weaver's loom always traces out a lower approximation of the convex function $$f(x) = 1 -2\sqrt{x} + x = (\sqrt{x} - 1)^2.$$ In particular, we can verify that $$f_N(x_i) = \frac{N-i}{N-1} - \frac{N-i}{i-1} x_i = \left( \frac{N-i}{i-1} \right)^2 = \left( \frac{i-1}{N-1} - 1\right)^2 = f(x_i),$$ and since $\frac{d}{dx}f(x_i) = -\frac{N-i}{i-1}$ for each $i = 2, \dots, N,$ by design, so we have confirmed that $f(x) \geq f_N(x)$ for all $N$ and $x \in [0,1]$ and the $f_N(x) \uparrow f(x)$ for all $x \in [0,1].$

Let's now go further and quadruple the number of bands placed on the weaving loom. In addition to the band connecting each $A_i$ and $B_i,$ you also place bands connecting $B_1$ and $C_1$, $C_1$ and $D_1$, and $D_1$ and $A_1$. You do this for all the sets of hooks from $1$ through $N,$ so that a total of $4N$ bands have been placed. When $N =100$, here is what the loom looks like:

As N increases, what fraction of the loom’s area lies between the four sets of bands? In other words, what fraction of the square above does the central white region make up?

We can skip to the end with our limiting curve of $f(x) = (\sqrt{x}-1)^2$ from the first portion of the problem, and then by symmetry take the area below the line $y = \frac{1}{2}$ and above $f(x)$ so long as $0 \leq x \leq \frac{1}{2}.$ This should give us one fourth of the answer. In particular, we see that the curve $y=f(x)$ intersects the line $y = \frac{1}{2}$ at $x = \left( 1 \pm \frac{\sqrt{2}}{2} \right)^2 = \frac{3}{2} \pm \sqrt{2}$ where only the negative sign gives a feasible answer less than $x = \frac{1}{2}$. Since we've defined the entire loom to have unit area, the fraction of loom made up by the white area as $N \to \infty$ is given by $$A = 4 \int_{\frac{3}{2}-\sqrt{2}}^\frac{1}{2} \left( \frac{1}{2} - (\sqrt{x} - 1)^2 \right) \,dx = \left[ \frac{16}{3}x^{3/2} -2x^2 -2x \right]_{\frac{3}{2} - \sqrt{2}}^\frac{1}{2} = \frac{8\sqrt{2}-10}{3} = 0.43790...$$

Sunday, August 27, 2023

Fiddle Eagles, Fiddle!

You’re betting on the final two football games of the season for your home team, the Fiddle-delphia Eagles. Thanks to the wonders of time travel, you happen to know that the Eagles will win one game and lose the other. Unfortunately, you can’t remember in which order they do so. Maybe the Eagles win the first game and lose the second, or maybe they lose the first and win the second.

You have $\$100$, of which you can bet any amount (including fractions of pennies) that the Eagles will win. So if you bet $x$ dollars on the first game and the Eagles win, you’ll have $100+x$ dollars to bet on the second game. But if the Eagles lose that first game, you’re left with $100−x$ dollars to bet on the second game.

You want to implement a betting strategy that guarantees you’ll have as much money as possible after both games. If you did so, then after the two games how much money would you be guaranteed to have?

In this case, where you know there are only two outcomes for the final two games (WL or LW), then you know with perfect clarity what the outcome of the final game is once you observe the outcome of the first game. Now here's where we get into some semantics, what exactly does "you're betting ... for your home team" mean? If you are just betting for either the Figgles as they are affectionately known or their opponents, then you can end up with a guaranteed $\$200$ by betting nothing on the first game, then doubling up on the second game with the sure lock. However, that wouldn't be a very fun answer, so let's instead assume that we can only bet on the Figgles to win and that the question involves deciding how much to optimally bet for the first game and the second game.

Assume that we bet $x \in [0,100]$ on the first game, observe outcome $o \in \{W, L\}$ and then bet $y \in [0, U(x,o)]$ where $$U(x,o) = \begin{cases} 100+x, &\text{if $o = W$;}\\ 100-x, &\text{if $o = L$}\end{cases}$$ on the second game. Since we know that if $o = W,$ then the Figgles will lose the second game and vice versa, we see that the final money balance will be $$V(x, y, o) = \begin{cases} 100 + x - y, & \text{if $o = W$;}\\ 100 - x + y & \text{if $o = L$}\end{cases}$$ then the problem becomes $$\max_{x, y} \min \{ V(x,y, W), V(x,y, L) \}.$$ Since this is multistage, we should first optimize the choice of $y$ in each case. In particular $\hat{y}(W) = 0,$ since if the Figgles won the first game they will lose the second and $\hat{y}(L) = 100 -x,$ since you might as well double up everything on the sure win knowing that the Figgles lost the first game.

So we can reduce the problem by introducing $$\hat{V}(x,o) = V(x, \hat{y}(o), o) = \begin{cases} 100 + x, &\text{if $o = W$;}\\ 2 ( 100 - x ), &\text{if $o = L$}\end{cases}$$ and then solving for the optimal strategy we get an ending money balance of $$\max_{x \in [0,100]} \min \{ \hat{V}(x, W), \hat{V}(x, L) \} = \max_{x \in [100]} \min \{ 100 -x, 200 - 2x \} = 133.\bar{3}$$ when originally wagering $\hat{x} = 33.\bar{3}$ on the first game.

Monday, August 14, 2023

Seeing the forest for the cylinders

You find yourself amidst what appears to be an infinite grid of trees. For the purposes of this puzzle, let’s suppose each tree is a perfect cylinder. You are at the point $(0, 0),$ but there’s a tree with a radius of $r_1 = 0.25$ units (and diameter $0.5$ units) centered at every other point in the plane with integer coordinates.

Of course, you can’t actually see infinitely many trees. Most of them are obscured by the trees immediately around you. As you look around in all directions, how many distinct trees are you able to see?

Let's set up the generic problem, with some unknown radius $r \gt 0,$ then we can try to solve each of the pieces of this fiddle, er, riddle.

Assume that I am sitting at the origin and I look along the line $y=m x.$ If we assume for the time being that each of these perfectly cylindrical trees were see through, then I could see a tree centered at $(a,b) \in \mathbb{Z}^2$ if and only if the set $$\{ (x,y) \mid y = mx, (x-a)^2 + (y-b)^2 = r^2 \} \ne \emptyset.$$ Simplifying a bit, I could see any tree centered at $(a,b)$ provided that $$(x-a)^2 + (mx - b)^2 -r^2 = (1+m^2) x^2 -2( a + bm) x + (a^2 + b^2 - r^2) = 0$$ has a solution, that is, if and only if the discriminant \begin{align*}0 \leq \Delta( m \mid a, b, r ) &= 4(a + bm)^2 - 4(1 + m^2) (a^2 + b^2 - r^2) \\ &= 4 ( -(b^2 - r^2) + 2 ab m - (a^2 - r^2) m^2 ).\end{align*} Rearranging a bit, and solving for $m$ we see that these translucent trees would be visible if and only if $$\frac{ab - r \sqrt{(a+b)^2 - r^2}}{a^2 - r^2} \leq m \leq \frac{ab + r \sqrt{(a+b)^2 - r^2}}{a^2 - r^2}.$$ However, since we don't have translucent cylindrcal trees, if we are looking along $y = mx$ then we could only see the two trees in $$(\hat{a}(m), \hat{b}(m)) \in \arg\min \left\{ |a| + |b| \left|\right. \frac{ab - r \sqrt{(a+b)^2 - r^2}}{a^2 - r^2} \leq m \leq \frac{ab + r \sqrt{(a+b)^2 - r^2}}{a^2 - r^2} \right\}.$$ Due to all of the symmetry of this problem, only method is to allow $m$ to slowly increase from $m = 0$ to $m = 1,$ and then rely on symmetry (since there is nothing uniquely special about the trees in the lower half of the first quadrant) and inclusion/exclusion (since some of the trees will be double counted) to answer either the question of how many tress do we see or which trees is furthest away.

So in particular, we see that for $m \in [0, \frac{r}{\sqrt{1-r^2}}],$ I would be looking at the tree at $(1,0).$ Similarly, for any $m \in [\frac{1-r\sqrt{2-r^2}}{1-r^2}, 1],$ I would be looking at the tree centered at $(1,1).$ So in particular for $r = 0.25,$ we have filled in the set $$ m \in [0, \frac{\sqrt{15}}{15}] \sqcup [\frac{16-\sqrt{31}}{15}, 1]$$ covered by $(1,0)$ and $(1,1).$ The next smallest tree (based on the $1$-norm) is centered at $(2,1),$ which can be seen for any $m \in [ \frac{32-\sqrt{79}}{63}, \frac{32 + \sqrt{79}}{63} ].$ At this point we still have only filled a disjoint union of intervals with $(1,0),$ $(1,1)$ and $(2,1),$ so filling in the remaining gaps, in the translucent tree problem we would be able to see the tree centered at $(3,1)$ for any $m \in [\frac{48-\sqrt{159}}{143}, \frac{48+\sqrt{159}}{143} ],$ but since $\frac{48 + \sqrt{159}}{143} \gt \frac{32 - \sqrt{79}}{63} \gt \frac{\sqrt{15}}{15} \gt \frac{48-\sqrt{159}}{143}$, I can only see the tree $(3,1)$ for $m \in (\frac{\sqrt{15}}{15}, \frac{32 - \sqrt{79}}{63}).$ Similarly, I can see $(3,2)$ for any $m \in (\frac{48 + \sqrt{159}}{143}, \frac{16-\sqrt{31}}{15}),$ so in totality there are 8 trees in the lower half of the first quadrant that can be seen, that is, $$T(m) = \begin{cases} (1,0), & m \in [0, \frac{\sqrt{15}}{15}]; \\ (3, 1), & m \in ( \frac{\sqrt{15}}{15}, \frac{48 - \sqrt{159}}{143}); \\ (2, 1), & m \in [ \frac{48 - \sqrt{159}}{143}, \frac{48 + \sqrt{159}}{143} ];\\ (3,2), & m \in (\frac{48 + \sqrt{159}}{143}, \frac{16-\sqrt{31}}{15}); \\ (1,1), & m \in [\frac{16 - \sqrt{31}}{15}, 1].\end{cases}$$

So since there are 5 in the lower half of the first quadrant, we should multiply by 8 to get to 40 trees in the whole plane. However, this would double count the eight points $(\pm 1, 0),$ $(0, \pm 1),$ $(\pm 1, \pm 1),$ so we need to subtract 8 from the total, leaving $32$ trees of diameter $r=0.25$ can be seen from the origin.