#### Problem

From our friends at the Riddler, where should you sit to catch a free t-shirt?

During a break at a music festival, the crew is launching T-shirts into the audience using a T-shirt cannon. And you’re in luck — your seat happens to be in the line of flight for one of the T-shirts! In other words, if the cannon is strong enough and the shirt is launched at the right angle, it will land in your arms.

The rows of seats in the audience are all on the same level (i.e., there is no incline), they are numbered 1, 2, 3, etc., and the T-shirts are being launched from directly in front of Row 1. Assume also that there is no air resistance (yes, I know, that’s a big assumption). You also happen to know quite a bit about the particular model of T-shirt cannon being used — with no air resistance, it can launch T-shirts to the very back of Row 100 in the audience, but no farther.

The crew member aiming in your direction is still figuring out the angle for the launch, which you figure will be a random angle between zero degrees (straight at the unfortunate person seated in Row 1) and 90 degrees (straight up). Which row should you be sitting in to maximize your chances of nabbing the T-shirt?

#### Answer

**Sit in the last row!** You’ve got a 9.01% chance of getting the t-shirt!

#### Simulation

My son says the proper approach to this problem is to buy a t-shirt cannon and start firing t-shirts. It’s hard to argue with this notion, but this is as close as I can come to that:

```
library("tidyverse")
df <- tibble(theta = runif(n = 10000, min = 0, max = pi / 2)) %>%
mutate(distance = 100 * sin(2 * theta))
df_summary <- df %>%
count(row = ceiling(distance))
```

#### Formulation

The angle of the t-shirt cannon is a random uniform variable, \(\Theta\), with a defined domain of \([0, \frac{\pi}{2}]\). (The domain piece will be important later on.) We can represent the probability density function \(f_{\Theta}\) and the cumulative distribution function \(F_{\Theta}\) as:

\[ \begin{aligned} f_{\Theta}(\theta) & = \frac{1}{\frac{\pi}{2}} = \frac{2}{\pi}, && 0 \le \theta \le \frac{\pi}{2} \\ F_{\Theta}(\theta) & = \int_0^{\theta} f_{\Theta}(u) \; du \\ & = \frac{2\theta}{\pi} \end{aligned} \]

We’ll represent the distance the t-shirt travels as a random variable \(X\). But first, we need to establish the relationship of the distance as a function of the angle \(\theta\). We’ll start on that path by looking at the height as a function of angle and time after launch:

\[ \begin{aligned} v(t) & = v_0 - gt \\ v_Y(\theta) & = v \sin{\Theta} \\ y(t) & = \int_0^t (v_y(\theta) - gu) \; du \\ & = \int_0^t (v \sin{\theta} - gu) \; du \\ & = vt \sin{\theta} - \frac{1}{2}gt^2 \\ \end{aligned} \]

The time \(T\) that the t-shirt is in flight and the distance \(X\) that the t-shirt travels are both random variables that are transformations of the angle \(\Theta\).

\[ \begin{aligned} 0 & = vT\sin{\Theta} - \frac{1}{2}gT^2 \\ T & = \frac{2v}{g}\sin{\Theta} \\ \\ X & = v_X(\Theta) \cdot T \\ & = v \cos{\Theta} \cdot \frac{2v}{g}\sin{\Theta} \\ & = \left(\frac{v^2}{g}\right) \cdot 2 \sin{\Theta} \cos{\Theta} \\ & = \left(\frac{v^2}{g}\right) \sin{2\Theta} \\ \end{aligned} \]

How can we use the maximum distance \(x_{\max} = 100\)?

\[ \begin{aligned} x_{\max} & = \max_{0 \le \theta \le \frac{\pi}{2}} \left(\frac{v^2}{g}\right) \sin{2\theta} \\ & = \frac{v^2}{g}, &\text{where } \theta = \frac{\pi}{4} \\ \end{aligned} \]

This gives us a convenient alternative transformation \(h\) for the distance \(X\) as a function of the angle \(\Theta\), without having the t-shirt’s launch velocity \(v\) or the gravity constant \(g\) in our formulae. (We used this expression in our simulation code above):

\[ \begin{aligned} X & = \left(\frac{v^2}{g}\right) \sin{2\Theta} \\ & = x_{\max} \sin{2\Theta} \\ & = h(\Theta) \\ \end{aligned} \]

We’re going to need to invert the function \(h\) to proceed, and that’s a problem, since it’s not invertible over the domain \([0, \frac{\pi}{2}]\). Instead, we’re going to look at a subset of that domain – \([0, \frac{\pi}{4}]\) – where we can invert \(h\), and then use the symmetry to help us.

\[ \begin{aligned} X & = h(\Theta), && 0 \le \Theta \le \frac{\pi}{4} \\ & = x_{\max}\sin{2\Theta} \\ \\ \Theta & = h^{-1}(X) \\ & = \frac{1}{2}\arcsin{\left(\frac{X}{x_{\max}}\right)} \end{aligned} \]

Now, we can return to our cumulative distribution function \(F_{\Theta}(\theta)\). But we’re making a slight modification, to account for our more limited domain. Then, we can develop a corresponding cdf for \(F_X(x)\):

\[ \begin{aligned} F_{\Theta}(\theta) & = \frac{4\theta}{\pi}, && 0 \le \Theta \le \frac{\pi}{4} \\ \\ F_X(x) & = \Pr(X \le x) \\ & = \Pr(\Theta \le h^{-1}(x)) \\ & = F_{\Theta}(h^{-1}(x)) \\ \\ & = F_{\Theta}\left(\frac{1}{2}\arcsin{\left(\frac{x}{x_{\max}}\right)}\right) \\ & = \left(\frac{4}{\pi}\right)\left(\frac{1}{2}\arcsin{\left(\frac{x}{x_{\max}}\right)}\right) \\ & = \left(\frac{2}{\pi}\right)\arcsin{\left(\frac{x}{x_{\max}}\right)} \\ \end{aligned} \]

We can use this cdf to discretize to a probability mass function for the
probability of the t-shirt arriving in row \(R\). There are a few ways to
think about this, but I’m basically using a `ceiling`

function on the
distance to translate to rows. (Hopefully consistent with “the back of
row 100”.)

\[ \begin{aligned} p_R(r) = F_X(r) - F_X(r - 1) \end{aligned} \]

We can encode these formulae, and generate probabilities for each row:

```
cdf_x <- function(x) {
x_max <- 100
return(2 / pi * asin(x / x_max))
}
pmf_r <- function(r) { cdf_x(r) - cdf_x(r - 1) }
est_probs <- tibble(r = seq(1, 100)) %>%
mutate(prob = map_dbl(r, pmf_r))
```

In particular, we can see that the **probability for the last row is
\(p_R(100) = 9.01%\)%**, which
will where we will choose to sit!

#### Plotting estimates vs. simulations

We can now establish the probabilities of the t-shirt landing in each row. (We’ll find it compares pretty favorably to our simulation from earlier.)