What is the expected number of red apples left when all the green apples are picked?

Two arguments:

I. Brute Force

For $i\in \{0,1,\cdots, 60\}$ let $p_i$ denote the probability that exactly $i$ red ones remain. Then the answer we want is $$E=\sum_{i=0}^{60}i\times p_i$$

But $p_i$ is easily computed: we need the last apple drawn to be green, which has probability $\frac 4{64}$. Conditioned on that, we need all three of the remaining green ones to be drawn ahead of that one. But there were $63-i$ chosen before the last green (out of a possible $63$), three of which were also green. the number of ways to do that is $\binom {60}{60-i}=\binom {60}{i}$ out of a total number of combinations equal to $\binom {63}{63-i}=\binom {63}{i}$ Thus, the conditional probability is the ratio $$\frac {\binom {60}{i}}{\binom {63}{i}}=\frac {(63-i)\times (62-i)\times (61-i)}{63\times 62\times 61}$$ and $$p_i=\frac 4{64}\times \frac {(63-i)\times (62-i)\times (61-i)}{63\times 62\times 61}$$

Sanity checks: let's compute $p_{60}$. The only way all the red apples can be left behind is if the first $4$ were green. The probability of that is $\frac 4{64}\times \frac 3{63}\times \frac 2{62}\times \frac 1{61}$ which matches the result of the formula. it is also a simple matter (at least with a machine) to confirm that $\sum p_i=1$.

Now it's easy to compute $E$ directly (using a machine, at least). We get $$\boxed {E=12}$$

II. Symmetry

Working backwards, the answer is the expected gap between the end of the string of apples and the last green apple drawn. But the expected lengths of the gaps are all the same...there are $5$ gaps in all, hence $E=\frac {60}{5}=12$

To gain intuition on the symmetry, I find it useful to imagine that there was one blue apple in the mix. You then arrange the, now $65$ apples in a circle. It's clear I think that, in this context, the red strings should all have expected length $12$. You obtain a linear order for your original $64$ apples by deleting the blue one and straightening out the circle.


By symmetry, the number of red apples left after all the $4$ green ones have been picked will (by looking at it in reverse) be the same as the number of red apples picked before the $1st$ green apple.

Let $X_i$ be an indicator random variable,
that is $=1$ if the $i_{th}$ red apple was drawn before the first green apple, and $0$ otherwise.

Each red apple is equally likely to be drawn before the first green apple,
so P($i_{th}$ red apple is drawn before the first green one) $= \frac15$

Now the expectation of an indicator r.v. is just the probability of the event it indicates, so $E[X_i] = \frac15$

By linearity of expectation we have expectation of sum = sum of expectations,
$E[\sum{(X_i)}] = \sum{E(X_i)} = \dfrac{60}{5} = 12$


Suppose we have $G$ green apples and $R$ red apples and ask about the number of red apples left when all green apples have been picked.

The probability of the last green apple being picked as apple number $q$ is

$${R+G\choose R}^{-1} {q-1\choose G-1}.$$

We now verify that this is indeed a proability. We use the Egorychev method to evaluate the sum

$${R+G\choose R}^{-1} \sum_{q=G}^{R+G} {q-1\choose G-1}.$$

Introducing

$${q-1\choose G-1} = \frac{1}{2\pi i} \int_{|z|=\epsilon} \frac{1}{z^G} (1+z)^{q-1} \; dz$$

we obtain for the sum of the probabilities

$${R+G\choose R}^{-1} \frac{1}{2\pi i} \int_{|z|=\epsilon} \frac{1}{z^G} \frac{1}{1+z} \sum_{q=G}^{R+G} (1+z)^q \; dz \\ = {R+G\choose R}^{-1} \frac{1}{2\pi i} \int_{|z|=\epsilon} \frac{1}{z^G} (1+z)^{G-1} \sum_{q=0}^{R} (1+z)^q \; dz \\ = {R+G\choose R}^{-1} \frac{1}{2\pi i} \int_{|z|=\epsilon} \frac{1}{z^G} (1+z)^{G-1} \frac{(1+z)^{R+1}-1}{1+z-1} \; dz \\ = {R+G\choose R}^{-1} \frac{1}{2\pi i} \int_{|z|=\epsilon} \frac{1}{z^{G+1}} (1+z)^{G-1} ((1+z)^{R+1}-1) \; dz$$

This has two pieces namely $[z^G] (1+z)^{R+G}$ and $[z^G] (1+z)^{G-1}$ and we get

$${R+G\choose R}^{-1} {R+G\choose G} = 1.$$

So we indeed have a probability here.

Continuing with the expectation we find

$${R+G\choose R}^{-1} \sum_{q=G}^{R+G} {q-1\choose G-1} (R+G-q) \\ = R+G - {R+G\choose R}^{-1} \sum_{q=G}^{R+G} q {q-1\choose G-1} \\ = R+G - G {R+G\choose R}^{-1} \sum_{q=G}^{R+G} \frac{q}{G} {q-1\choose G-1} \\ = R+G - G {R+G\choose R}^{-1} \sum_{q=G}^{R+G} {q\choose G}.$$

Introducing

$${q\choose G} = \frac{1}{2\pi i} \int_{|z|=\epsilon} \frac{1}{z^{G+1}} (1+z)^{q} \; dz$$

we obtain for the sum component of the expectation

$$\frac{1}{2\pi i} \int_{|z|=\epsilon} \frac{1}{z^{G+1}} \sum_{q=G}^{R+G} (1+z)^q \; dz \\ \frac{1}{2\pi i} \int_{|z|=\epsilon} \frac{1}{z^{G+1}} (1+z)^G \sum_{q=0}^{R} (1+z)^q \; dz \\ \frac{1}{2\pi i} \int_{|z|=\epsilon} \frac{1}{z^{G+1}} (1+z)^G \frac{(1+z)^{R+1}-1}{1+z-1} \; dz \\ \frac{1}{2\pi i} \int_{|z|=\epsilon} \frac{1}{z^{G+2}} (1+z)^G ((1+z)^{R+1}-1) \; dz.$$

We have the two pieces $[z^{G+1}] (1+z)^{G+R+1}$ and $[z^{G+1}] (1+z)^G$ and obtain

$${R+G+1\choose G+1}.$$

Returning to the expectation we have

$$R+G - G {R+G\choose R}^{-1} {R+G+1\choose G+1} \\ = R+G - G \frac{(R+G+1)! \times R! \times G!}{(R+G)! \times (G+1)! \times R!}.$$

This simplifies to

$$\bbox[5px,border:2px solid #00A000]{ R+G - G \frac{R+G+1}{G+1} = R - G \frac{R}{G+1} = \frac{R}{G+1}.}$$

In particular for $4$ green apples and $60$ red apples we get

$$64- 4\frac{65}{5} = 64 - 4\times 13 = 12 = \frac{60}{5}.$$

This formula may be verified with the following Maple code (warning -- total enumeration, use on small values for the number of apples)

with(combinat);

X :=
proc(G, R)
    option remember;
    local perm, src, pos, seen, res;

    src :=
    [seq(GG, q=1..G), seq(RR, q=1..R)];

    res := 0;

    for perm in permute(src) do
        seen := 0;

        for pos to R+G do
            if perm[pos] = GG then
                seen := seen + 1;

                if seen = G then
                    break;
                fi;
            fi;
        od;

        res := res + (R+G)-pos;
    od;

    res/binomial(R+G, R);
end;

Y :=(G, R) -> R/(G+1);