Processing math: 66%

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 (2k,1), before finishing at (2,2), for some 0h,k1.

The time elapsed in minutes by Alice for this path is T(h,k)=109(1+h2+1+k2)+(1h)2+(1k)2. Taking the the gradient of the time elapsed function gives T=(10h91+h21h(1h)2+(1k)210k91+k21k(1h)2+(1k)2). Setting the partial derivative with respect to h to zero, we get 10h91+h2=1h(1h)2+(1k)2. Setting the partial derivative with respect to k to zero, we get 10k91+k2=1k(1h)2+(1k)2. Combining these, we see that this would imply that h(1h)1+h2=k(1k)1+k2, which since f(x)=x(1x)1+x2 is monotonically increasing for x0 implies that h=k. In this case, we get that we must have 10h91+h2=1h(1h)2+(1h)2=12, or equivalently h1+h2=9220. Squaring both sides and solving for h, we get h2(181200)=81200, which give an optimal value of h=k=9119. Plugging back into the time elapsed, shows that Alice can get reach the finish optimally in T=T(9119,9119)=2091+81119+(19119)2+(19119)2=20029119+2(19119)=2119(20099+119)=2(1+1199)3.12835...minutes.

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 h1,,h14 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., h1=h14, h2=h13, , h7=h8).

In this case, we find that the time elapsed by Alice in minutes is ˜T(h1,,h7)=209(1+h21+3i=1h22i+h22i+1)+2(1h1)2+(1h2)2+2(1h3)2+(1h4)2+2(1h5)2+(1h6)2+2(1h7).

In this case we can take the gradient of ˜T and get ˜T(h)=(20h191+h212(1h1)(1h1)2+(1h2)220h29h22+h232(1h2)(1h1)2+(1h2)220h39h22+h232(1h3)(1h3)2+(1h4)220h49h24+h252(1h4)(1h3)2+(1h4)220h59h24+h252(1h5)(1h5)2+(1h6)220h69h26+h272(1h6)(1h5)2+(1h6)220h79h26+h272). Let's first assume that there is some solution ˆh in the interior of [0,1]7, where ˜T is infinitely differentiable. If we set the gradient to zero and solve for the last equation, we get that h27h26+h27=81200, which implies that h26h26+h27=119200. Plugging this back into the second to last coordinate, we get that (1h6)2(1h5)2+(1h6)2=1440081119200=119162, which in turn implies that (1h5)2(1h5)2+(1h6)2=43162. Plugging this into the third to last coordinate, we get that h25h24+h25=81400443162=43200, which implies that h24h24+h25=157200. Plugging this into the next coordinate, we get that (1h4)2(1h3)2+(1h4)2=1440081157200=157162, which implies that (1h3)2(1h3)2+(1h4)2=5162. Continuing onward, this implies that h23h22+h23=8140045162=140, which in turn means that h22h22+h23=3940. Plugging this value into the second coordinate and solving gives (1h2)2(1h1)2+(1h2)2=14400813940=6554; however, this is a contradiction since for any a,bR, a2a2+b21. 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 h7 to something nonzero, we will arrive at similar contradictions unless we have h4=h5=h6=h7=0, since if let's say that h4>0=h5, then since the normal cone of [0,1]7 at h is given by N[0,1]7(h)={yR7yihi=0} in order for h to be an optimizer of ˜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 01h4(1h3)2+(1h4)21 for all values of h3,h4[0,1] we will be hard pressed to solve. So let's then reduce the problem to optimizing the further reduced function ˇT(h1,h2,h3)=˜T(h1,h2,h3,0,0,0,0)=209(1+h21+h22+h23)+(1h1)2+(1h2)2+1+(1h3)2+32 over [0,1]3.

Here again, we have the reduced and slightly modified gradient ˇT=(20h191+h212(1h1)(1h1)2+(1h2)220h29h22+h232(1h2)(1h1)2+(1h2)220h39h22+h232(1h3)1+(1h3)2). Since this still yields some gnarly system of quadratics, at this point, though you can also just give up and program it, finding ˆh=(0.485699,0.0737739,0.057801) which yields an optimal value of ˇT=˜T=11.78815 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 t1=t1(t,v2), 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, v2. 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 t10tv2 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 v2+110, we have t1=t110v2110+v2=t110v21+10v2. Additionally of note, Alice and her second siblings meeting occurs d=d(t,v2)=(t+t1)v2=tv2(1+110v21+10v2)=2tv21+10v2 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 t2=t2(t,v2)=1d(t,v2)0.1=1010d=1020tv21+10v2 minutes. So Alice and one sibling will arrive at TA=TA(t,v2)=t+t1(t,v2)+t2(t,v2)=t+t110v21+10v2+1020tv21+10v2=10+t(1+10v2)+t(110v2)20tv2)1+10v2=10+2t20tv21+10v2=10+2t110v21+10v2 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 v1 and will arrive home at T1=T1(t,v1)=t+1t10v1=1v1t110v110v1. So the time when all of the siblings are safely home and devouring pancakes for dinner is T=T(t,v1,v2)=max 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*}