Sunday, April 25, 2021

The perfect nonagonal pancake

After you intended to make a perfectly circular pancake, the batter has spread out, filling every last corner of your square pan. (It is unclear why you were using a square pan in the first place.)

To salvage your breakfast, you plan to slice off the corners of your square pancake, giving you something closer to a circle. The image below shows one such slice you might make. Each slice must be straight, and no slice can pass through the inscribed blue circle that represents your original desired pancake.

Of course, there’s a catch. You can make at most five slices. If the blue circle has a radius of 1 unit, what is the minimum possible area your pancake can have after five slices?

By symmetry we can break the problem into quandrants. Three quadrants will have symmetric cuts, the fourth quadrant will have two cuts in it. Let's first focus on the three symmetric quadrants:

If we make a cut that is tangent to the blue circle at the point $(t, \sqrt{1-t^2})$ then the cut would be given by the line $xt + y\sqrt{1-t^2}=1.$ This line would intersect the line $y=1$ at the point $(\frac{1-\sqrt{1-t^2}}{t}, 1)$ and the line $x=1$ at the point $(1, \frac{\sqrt{1-t^2}}{1+t}).$ The remaining pancake area is then given by $$A(t) = \frac{1-\sqrt{1-t^2}}{t} + \frac{1}{2} \left( 1 - \frac{1 - \sqrt{1-t^2}}{t}\right) \left( 1 + \frac{\sqrt{1-t^2}}{1+t} \right) = \frac{1+t -\sqrt{1-t^2}}{t(1+t)}.$$ Differentiating with respect to $t$ we get $$A^\prime(t) = \frac{1+t-t^2 -(1+t)\sqrt{1-t^2}}{t^2(1+t)\sqrt{1-t^2}}.$$ Setting to zero and solving for $t$, we get $t^* = \frac{1}{\sqrt{2}},$ with minimal area $A(1/\sqrt{2}) = 2(\sqrt{2}-1).$

For the fourth quadrant, where we make two cuts assume that these cuts are tangent to $(r,\sqrt{1-r^2})$ and $(s,\sqrt{1-s^2}),$ respectively, which would be associated with cuts $$xr + y\sqrt{1-r^2}=1 \,\, \text{and} \,\, xs + y\sqrt{1-s^2} = 1.$$ Without loss of generality, if $r \leq s$, then the line $xr+y\sqrt{1-r^2}=1$ intersects the line $y=1$ at $(\frac{1-\sqrt{1-r^2}}{r},1),$ the line $xs+y\sqrt{1-s^2}=1$ intersects the line $x = 1$ at $(1,\frac{\sqrt{1-s^2}}{1+s}),$ and the two cuts intersect at $(\frac{\sqrt{1-r^2} - \sqrt{1-s^2}}{s-r}, \frac{s\sqrt{1-r^2} + r\sqrt{1-s^2}}{r+s}).$ The area of the the remaining pancake region is then given by \begin{align*}B(r,s) &= \frac{1-\sqrt{1-r^2}}{r}\\ &\,\,+ \frac{1}{2} \left(1 + \frac{s\sqrt{1-r^2} + r\sqrt{1-s^2}}{s+r}\right) \left(\frac{\sqrt{1-r^2} - \sqrt{1-s^2}}{s-r} - \frac{1 - \sqrt{1-r^2}}{r}\right)\\ &\,\,\,\, + \frac{1}{2} \left(\frac{s\sqrt{1-r^2} + r\sqrt{1-s^2}}{s+r} + \frac{\sqrt{1-s^2}}{1+s}\right) \left(1 - \frac{\sqrt{1-r^2} - \sqrt{1-s^2}}{s-r}\right)\end{align*} With some additional algebra and differentiation, we obtain optimal values of $r^* = \frac{1}{2}$ and $s^* = \frac{\sqrt{3}}{2},$ which gives $B(\frac{1}{2}, \frac{\sqrt{3}}{2}) = 3(2 - \sqrt{3}).$

Putting these together we get a minmal pancake area of $$3A(1/\sqrt{2}) + B(1/2,\sqrt{3}/2) = 3(2(\sqrt{2}-1)) + 3(2 - \sqrt{3}) = 3(2\sqrt{2}- \sqrt{3}).$$

Sunday, April 18, 2021

Bop It! Twist It! .... Pixm It?

You are creating a variation of a Romulan pixmit deck. Each card is an equilateral triangle, with one of the digits 0 through 9 (written in Romulan, of course) at the base of each side of the card. No number appears more than once on each card. Furthermore, every card in the deck is unique, meaning no card can be rotated so that it matches (i.e., can be superimposed on) any other card.

What is the greatest number of cards your pixmit deck can have?

There are $\binom{10}{3} = 120$ different combinations of three distinct digits from $0$ to $9$. There are two distinct ways (up to rotation of the equilateral triangle) to order these three distinct digits. (We can see this by say labeling the sides in ascending order either clockwise or counter-clockwise.) This gives a total of $240$ distinct pixmit cards.

If doubles were allowed in the pixmit mix(mit), then there would be $90$ distinct ways to select the combinations ($10$ options for the doubled digit, $9$ options for the additional digit). In this case, all labelings are rotations of one another. You could through in another $10$ distinct cards if triples are allowed, which would bring the total up to $340$ unique pixmit cards if doubles and triples are allowed.

Wax On, Wane Off

After a new moon, the crescent appears to grow slowly at first. At some point, the moon will be one-sixth full by area, then one-quarter full, and so on. Eventually, it becomes a half-moon, at which point its growth begins to slow down. How many times faster is the area of the illuminated moon growing when it is a half-moon versus a one-sixth moon?

With the simplifying assumption that the sun is sufficiently far away and that the moon orbits Earth much faster than Earth orbits the Sun, we are left with the simplified system where the illuminated portion of the moon from the observer's viewpoint on Earth is a spherical segment of angle $\theta$ for $\theta \in [0, \pi]$ (when the Moon is waxing).

Let's set up coordinates such that the $y$-axis is pointing towards the observer on Earth, and the $x$- and $z$-axis in the plane bounding the hemisphere that is visible from Earth. If the angle between the plane normal to the ray from the Moon to the Sun and the plane normal to the ray from the Moon to the Earth is $\theta$, then the dividing line between darkness and light on the face of a presume perfectly spherical Moon would be parameterized as $$ \{ (R_\text{moon} \cos \theta \sin \phi, R_\text{moon} \sin \theta \sin \phi, R_\text{moon} \cos \phi) \,\, \mid \,\, 0 \leq \phi \leq \pi\},$$ where $\phi$ is the polar angle from the $z$-axis.

If we were just measuring how fast the illuminated surface area increases, then it wouldn't be much of a question since the surface area grows linearly in the angle $\theta$, so the speed that the illuminated surface area was growing at would be constant at both half- and one-sixth-moons. So instead, we need to project the curve on the spherical surface into the circle in the $xz$-plane. In particular, the boundary between the illuminated and dark regions would then be $$\{(R_\text{moon} \cos \theta \sin \phi, R_\text{moon} \cos \phi) \, \mid \, 0 \leq \phi \leq \pi \}.$$

Switching to rectilinear coordinates and assume that we change units of measurement such that $R_\text{moon} = 1,$ we can calculate the illuminated area as $$I(\theta) = (1- \cos \theta) \int_{-1}^1 \sqrt{1-y^2} \, dy = \frac{\pi}{2} (1 - \cos \theta).$$ The rate of change of the illuminated area is given by $$\frac{dI}{d\theta} = \frac{\pi}{2} \sin \theta.$$

The moon is one-sixth illuminated when $I(\theta) = \pi \frac{1 - \cos \theta}{2} = \frac{\pi}{6},$ or equivalently, $\theta_{1/6} = \arccos \frac{2}{3}.$ So the illuminated area is growing a rate of $$\frac{dI}{d\theta} (\theta_{1/6}) = \frac{\pi}{2} \sin \left( \arccos \frac{2}{3} \right) = \frac{ \pi \sqrt{5}}{6}.$$ The moon is half illuminated when $\theta_{1/2} = \frac{\pi}{2},$ where the rate of change is $$\frac{dI}{d\theta} (\theta_{1/2})= \frac{\pi}{2}.$$ Therefore, the illuminated area is growing $\frac{\frac{\pi}{2}}{\frac{\pi \sqrt{5}}{6}} = \frac{3}{\sqrt{5}} \approx 1.34164\dots$ times faster when half full than one-sixth full.

Sunday, April 11, 2021

Always see the cup A as two-thirds full, eventually

You have two $16$-ounce cups — cup A and cup B. Both cups initially have $8$ ounces of water in them.

You take half of the water in cup A and pour it into cup B. Then, you take half of the water in cup B and pour it back into cup A. You do this again. And again. And again. And then many, many, many more times — always pouring half the contents of A into B, and then half of B back into A.

When you finally pause for a breather, what fraction of the total water is in cup A?

Let's solve the general case, as it will turn out that the particulars of the initial conditions will not particularly matter in this system of recurrence equations. Let's assume that you start out with $u \in [0,8]$ ounces in cup A and $v \in [0,8]$ ounces in cup B, with $u + v > 0.$ Let's define $V^A_n$ and $V^B_n$ as volumes of water in each cup after $n$ full rotations of pouring half of cup A into cup B and then half of cup B back into cup A. By construction, the recurrence relationship is thus \begin{align*}V_{n+1}^A &= \frac{1}{2} V_n^A + \frac{1}{2} \left( \frac{1}{2} V_n^A + V_n^B \right) = \frac{3}{4} V_n^A + \frac{1}{2} V_n^B \\ V_{n+1}^B &= \frac{1}{2} \left( \frac{1}{2} V_n^A + V_n^B \right) = \frac{1}{4} V_n^A + \frac{1}{2} V_n^B\end{align*}

Equivalently, if we let $V_n = (V_n^A, V_n^B)$ be the vector of volumes after $n$ rotations, then the matrix recurrence equation is $$V_n = \begin{pmatrix} \frac{3}{4} & \frac{1}{2} \\ \frac{1}{4} & \frac{1}{2} \end{pmatrix} V_{n-1},$$ or if we let $A = \begin{pmatrix} \frac{3}{4} & \frac{1}{2} \\ \frac{1}{4} & \frac{1}{2} \end{pmatrix},$ then have simply $$V_n = A^n V_0.$$ Using the eigendecomposition of $A,$ we get $A = Q\Lambda Q^{-1}$ where $Q = \begin{pmatrix} 2 & 1 \\ 1 & -1 \end{pmatrix}$ and $\Lambda = \begin{pmatrix} 1 & 0 \\ 0 & \frac{1}{4} \end{pmatrix}$ (and for good measure, $Q^{-1} = \begin{pmatrix} \frac{1}{3} & \frac{1}{3} \\ \frac{1}{3} & -\frac{2}{3} \end{pmatrix}$). As a result, we also have $$A^n = Q \Lambda^n Q^{-1} = Q \begin{pmatrix} 1 & 0 \\ 0 & 4^{-n} \end{pmatrix} Q^{-1},$$ so $$V_n = \begin{pmatrix} 2 & 1 \\ 1 & -1 \end{pmatrix} \begin{pmatrix} 1 & 0 \\ 0 & 4^{-n} \end{pmatrix} \begin{pmatrix} \frac{1}{3} & \frac{1}{3} \\ \frac{1}{3} & -\frac{2}{3} \end{pmatrix} V_0 = \begin{pmatrix} 2 \frac{u+v}{3} + 4^{-n} \frac{u-2v}{3} \\ \frac{u+v}{3} - 4^{-n} \frac{u-2v}{3} \end{pmatrix}.$$

Therefore, after $n$ rotations, the ratio of the volume in cup A to the total volume ($u+v > 0$) is $$r_n = \frac{2 \frac{u+v}{3} + 4^{-n} \frac{u-2v}{3}}{u+v} = \frac{2}{3} + \frac{4^{-n}}{3} \frac{u-2v}{u+v}.$$ As $n \to \infty,$ we have that this ratio will always converge to $r_n \to \frac{2}{3}$, regardless of the initial values of $u$ and $v$ (such that $u + v > 0$).

Monday, April 5, 2021

Sphinx hijinks

You will be asked four seemingly arbitrary true-or-false questions by the Sphinx on a topic about which you know absolutely nothing. Before the first question is asked, you have exactly $\$1.$ For each question, you can bet any non-negative amount of money that you will answer correctly. That is, you can bet any real number (including fractions of pennies) between zero and the current amount of money you have. After each of your answers, the Sphinx reveals the correct answer. If you are right, you gain the amount of money you bet; if you are wrong, you lose the money you bet.

However, there’s a catch. (Isn’t there always, with the Sphinx?) The answer will never be the same for three questions in a row.

With this information in hand, what is the maximum amount of money you can be sure that you’ll win, no matter what the answers wind up being?

Just before the $i$th question, let's assume that we have $S_{i-1}$ dollars. Further, let $x_i \in [0, S_{i-1}]$ be the wager and $u_i \in \{T, F\}$ be your answer for question $i.$ Finally let $\mathcal{T}_i = (t_1, \dots, t_i)$ be the historical truth values of the question up until question $i.$ We assume that $S_0 = 1$ and $\mathcal{T}_0 = \emptyset.$

Rather than the full binary tree of $16$ possible truth values to a sequence of $4$ true/false questions, the condition that the answer to three consecutive questions is never the same prunes the tree down to $10$ possible outcomes.

At each leaf $\mathcal{T} = \mathcal{T}_4$ of this tree, we can come up with the value of $S_4(x,u,\mathcal{T})$ at each leaf based on the strategies of $x = (x_1(S_0), \dots, x_4(S_3,\mathcal{T}_3)),$ $u = (u_1(S_0), \dots, u_4(S_3,\mathcal{T}_3)).$ The goal is to choose optimal strategies $$\hat{x}, \hat{u} \in \mathop{\arg\!\max} \left\{ \min_{\mathcal{T}} S_4(x,u,\mathcal{T}) \right\}.$$

We can quickly reduce the dimension by way of a smaller problem. Let's say instead that the Sphinx just had one question, with no restrictions on its truth value, but still allowed you to wager $x \in [0,S].$ In this case, since you have no additional information the choice of $u$ is arbitrary and with $50\%$ probabilty you could end up with $S+x$ and $50\%$ you could end up with $S-x.$ If this case, still wanting to maximize the minimum final wealth, we would select $$\hat{x} \in \mathop{\arg\!\max}\limits_{x\in[0,S]} \{ \min \{S+x,S-x\} \} = \{0\}.$$ By extension, we see that when presented with a true $50\% / 50\%$ proposition it is best "not to play the game".

Additionally, as with all sure bets, with perfect information (i.e., when we have already observed two T in a row and know that the next answer will be F, or vice versa) we should bet the house, thereby doubling the your money.

Combining these two examples, we can resolve the optimal behavior of the $4$th question and conclude that we should always bet $0$ on the first question as well. By symmetry, without loss of generality, let's assume that the Sphinx's first question was true. We can reduce the dimensionality further by allowing the bet size to assume negative values, as well, we can infer the optimal answer ($x \gt 0$ implies optimal answer for question 2 is T, vice versa).

Then we can analytically solve for the following optimization problem: $$\max_{-S_0 \leq x \leq S_0} \max_{-S_0 + x \leq y \leq S_0 - x} \min \Big\{ 2(S_0+x), S_0 - x + y, 2(S_0 - x -y) \Big\},$$ which is solved by $(\hat{x},\hat{y}) = (-\frac{S_0}{5}, \frac{2S_0}{5}),$ which gives the optimal minimal value of $$S_4(\hat{x},\hat{y}) = \frac{8S_0}{5} = 1.6,$$ meaing you can guarantee winning $\$0.60.$

Never go up against the game's creator, when pennies are on the line!

You and Wenjun are playing a game in which you alternate taking turns, removing pennies from a pile. On your turn, you can remove either one or two pennies from the pile. On Wenjun’s turn, he can remove either two or three pennies. Whoever takes the last penny loses. (If there is only one penny left and it’s Wenjun’s turn, then he skips his turn, which means you will lose). Suppose both you and Wenjun play optimally.

1) If you go first, then what initial numbers of pennies mean you will win the game?

2) If Wenjun goes first, then what initial numbers of pennies mean he will win the game?

Let $N$ be the number of initial pennies.

First, let's see that no matter who goes first, if there are $N=2$ initial pennies, the person who goes first will lose. (If Wenjun goes first, he must remove both of the pennies and loses right away. If I go first, then either I remove both of the pennies and lose right away or I can delay the inevitable by only removing one penny, but as per the note above then I will lose when Wenjun skips his turn.)

Similarly, if $N=1$, then I will lose regardless of who goes first, since Wenjun given himself the super power of being able to skip his turn in this case.

The losing behavior has a period of $4$ in the initial number of pennies. Let's say I go first, then regardless of my move, Wenjun can make a corresponding move to ensure that I am left with $N-4$ pennies to make my next move. Similarly, if Wenjun goes first, I can also make a corresponding move to make sure that his next move will be with a pile of $N-4$ pennies.

So for instance, since I will lose if I go first with $N \in \{1,2\},$ then I will in face lose whenever $N \in \{1,2\} + 4\mathbb{N}.$ To confirm that these are the only times I can lose, let's look at the converse. If $N \in 3 + 4\mathbb{N}$ then my first move should be to remove $1$ penny, so that Wenjun will start with a pile of pennies whose size is in $2 + 4\mathbb{N}.$ Similarly, if $N \in 4\mathbb{N}$ then my first move would be to remove $2$ pennies, again leaving Wenjun with a losing pile of pennies with size in $2 + 4\mathbb{N}.$ So if I go first, I will win whenever the initial size $N \in \{3,4\} + 4\mathbb{N}.$

Wenjun's advantage is that I lose whenever I start with a pile with since in $\{1,2\} + 4\mathbb{N}.$ To see this, if $N \in 1 + 4\mathbb{N},$ he will leave me with a pile with size in $2 + 4\mathbb{N}$ if he removes $3$ pennies with his first move. If $N \in \{3,4\} + 4 \mathbb{N}$ then he will leave me with a pile in $\{1,2\} + 4\mathbb{N}$ by removing $2$ pennies. So if Wenjun goes first, he will whenever the initial size $N \in \{1,3,4\} + 4\mathbb{N}.$

It just goes to show, that you should always be wary when quantum computing whiz kids propose that you play a mathematical game. Especially if they go first!