# Basketball Free-Throw Percentage

Source: https://cca.twango.dev/AP-Calculus-BC/Take-Home-Quizzes/quiz-01

# Basketball Free-Throw Percentage

## Prompt

In the sport of basketball, when a player is "fouled," they have the opportunity to take two "free-throws," where the
player shoots the ball two times and can give his team one point for each basket made

An important statistic in basketball is a player's free-throw success percentage over the basketball season. For
example, if a player has 10 free-throw attempts made 8 baskets, their percentage is 80%.

Interestingly, the percentage is always rounded to the nearest percent (for the ease of the viewing public, which
probably does not know math). For example, if a player has made 7 out of 22 free-throws, then the reported percentage is
32%.

During a game, the announcer says that a player is making 78% of their free throws at the moment that the player is
fouled. The player makes two free-throw attempts and makes the first one but misses the second attempt. After the
statistics are updated, the player is now making 76% of their free-throws.

For this player, what are all possible numbers of free-throws made and attempted so far this season (including the ones
that were just made)? (Hint: There are a finite number of solutions)

## Solution
The handwritten solution is transcribed below; [[../assets/take-home-quiz-1.pdf|the original six-page PDF]] preserves the working and diagrams.

## Verification
In Kotlin, the solution can be verified by running the following code:

```kotlin
fun calculatePercentages(
    percentInitial: Int,
    percentFinal: Int,
    successes: Int,
    rounds: Int,
    iterations: Int,
): MutableList<Pair<Int, Int>> {

    val solutions = mutableListOf<Pair<Int, Int>>();

    assert(iterations > 1) { "iterations $iterations must be greater than 1" };

    for (n in 1..iterations) {
        for (s in 1..n) {
            val rawPercent = s.toDouble() / n.toDouble();

            val percentRounded = Math.round(rawPercent * 100).toInt();

            val finalSuccesses = s + successes;
            val finalRounds = n + rounds;

            val rawFinalPercent = finalSuccesses.toDouble() / finalRounds.toDouble();
            val finalPercentRounded = Math.round(rawFinalPercent * 100).toInt();

            if (percentRounded == percentInitial && finalPercentRounded == percentFinal) {
                solutions.add(Pair(s, n));
            }

        }
    }

    return solutions;
}

//sampleStart
fun main() {
    val iterations = 1000;

    calculatePercentages(78, 76, 1, 2, iterations).forEach {
        println("initial: (${it.first}, ${it.second}); final: (${it.first + 1}, ${it.second + 2})")
    }
}
//sampleEnd
```

## Handwritten solution

### Terms and rounding requirements

Let $s$ be the initial successes and $n$ the initial attempts (called “rounds” in the source). The final totals are $(s+1,n+2)$.

$$
\frac{775}{1000}\leq\frac sn<\frac{785}{1000},
\qquad
\frac{755}{1000}\leq\frac{s+1}{n+2}<\frac{765}{1000}.
$$

Solving the first pair for $n$ gives

$$n\leq\frac{1000}{775}s,\qquad n>\frac{1000}{785}s.$$

For the updated percentage,

$$
\frac{755}{1000}n+\frac{151}{100}\leq s+1
<\frac{765}{1000}n+\frac{153}{100},
$$

so

$$
n\leq\frac{1000}{755}s-\frac{102}{151},
\qquad n>\frac{1000}{765}s-\frac{106}{153}.
$$

### Boundary intersections

Intersecting each initial boundary with each updated boundary gives:

| Initial boundary | Updated boundary | $(s,n)$ intersection |
|---|---|---|
| $n=1000s/775$ | $n=1000s/755-102/151$ | $(1581/80,51/2)\approx(19.7625,25.5)$ |
| $n=1000s/775$ | $n=1000s/765-106/153$ | $(1643/40,53)=(41.075,53)$ |
| $n=1000s/785$ | $n=1000s/755-102/151$ | $(2669/200,17)=(13.345,17)$ |
| $n=1000s/785$ | $n=1000s/765-106/153$ | $(8321/400,53/2)\approx(20.8025,26.5)$ |

![[assets/calculus-bc-free-throw-region.svg|Exact free-throw feasible region and six integer solutions]]

The graph is generated from the four stated inequalities. Solid boundaries are included; dashed boundaries are excluded. The region is very narrow in actual $(s,n)$ coordinates, unlike the exaggerated handwritten sketch. The right panel uses the vertical offset $n-1000s/775$ to show the same region more clearly; vertex and point labels still give the original $(s,n)$ totals.

Intuitively, the solutions are whole-number points $(s,n)$ in this quadrilateral, respecting the strict and nonstrict boundaries. The source bounds are $s\in[14,41]$ and $n\in(17,53)$.

### Iterating through the possibilities

The handwritten pseudocode:

```text
FOR s IN 14...41
    FOR n IN 17...53
        IF (s,n) SATISFIES INEQUALITIES
            ADD (s,n) TO SOLUTIONS
```

Personal note: “You can technically make this more efficient with flooring/ceiling the max/min values of the quadrilateral at X.”

The original written list is $(18,25),(21,27),(25,32),(28,36),(31,40),(38,49)$, followed by final totals $(19,27),(22,29),(26,34),(29,38),(32,42),(39,51)$.

> [!correction]
> The first pair was copied incorrectly in the handwritten answer list. Both plotted diagrams label it $(18,23)$. In fact, $18/25=72\%$, whereas $18/23\approx78.26\%$ and $19/25=76\%$. Integer arithmetic verifies exactly these six possibilities:
>
> | Initial made/attempted | Final made/attempted |
> |---|---|
> | $(18,23)$ | **$(19,25)$** |
> | $(21,27)$ | **$(22,29)$** |
> | $(25,32)$ | **$(26,34)$** |
> | $(28,36)$ | **$(29,38)$** |
> | $(31,40)$ | **$(32,42)$** |
> | $(38,49)$ | **$(39,51)$** |

### Desmos verification

The source uses $s=\operatorname{round}(x)$ and $n=\operatorname{round}(y)$ to highlight integer pairs satisfying the inequalities. “Intersections match iterative solutions.” The four boundaries form the quadrilateral above and diverge as $s$ gets larger.

![[assets/calculus-bc-free-throw-solutions.svg|Initial and updated free-throw totals]]

Exact integer solutions replace the Desmos interface screenshot. Each segment joins an initial pair $(s,n)$ to its final pair $(s+1,n+2)$, including the corrected first answer described above.

Related: [[quiz-02|Derivative perspectives]].

## Reading the boundaries

The initial-percentage conditions are the editable inequalities above: $n\leq1000s/775$ and $n>1000s/785$. The updated conditions are $n\leq1000s/755-102/151$ and $n>1000s/765-106/153$. The combined figure preserves the information in the separate handwritten boundary sketches:

| Intersection shown in the original sketches | Boundary pair | Allowed side |
|---|---|---|
| Lower-left included-boundary intersection $(19.7625,25.5)$ | The two $\leq$ boundaries | Below both lines |
| Upper-right vertex $(41.075,53)$ | Initial $\leq$ and updated $>$ boundaries | Below the solid line and above the dashed line |
| Lower vertex $(13.345,17)$ | Updated $\leq$ and initial $>$ boundaries | Below the solid line and above the dashed line |
| Right-side intersection $(20.8025,26.5)$ | The two $>$ boundaries | Above both dashed lines |

The separate inequality crops repeat the equations already transcribed, and the small intersection sketches are consolidated into the exact region plot. The original handwritten versions remain in the linked PDF.
