<s>[INST] What is the average distance between the first occurence of an element and the first occurence of another after that one? We have a set of Na elements 'a' and Nb elements 'b'.
For example for Na=2 and Nb=2 it would be (a, a, b, b).
We can generate all possible permutations with them. In our example we will end up having 24, some could be the same.
Now, for each of this "vectors" we can measure the distance between the first occurence of 'a' and the first occurence of 'b' happenning after that 'a'.
(We have capitalized that occurrences)
(A,B,a,b) = 2-1 = 1
(A,B,a,b) = 2-1 = 1
(A,B,a,b) = 2-1 = 1
(A,B,a,b) = 2-1 = 1
(A,B,b,a) = 2-1 = 1
(A,B,b,a) = 2-1 = 1
(A,B,b,a) = 2-1 = 1
(A,B,b,a) = 2-1 = 1
(A,a,B,b) = 3-1 = 2
(A,a,B,b) = 3-1 = 2 
(A,a,B,b) = 3-1 = 2
(A,a,B,b) = 3-1 = 2
(b,A,B,a) = 2-1 = 2
(b,A,B,a) = 2-1 = 2
(b,A,B,a) = 2-1 = 1
(b,A,B,a) = 2-1 = 1
(b,A,a,B) = 3-1 = 2
(b,A,a,B) = 3-1 = 2
(b,A,a,B) = 3-1 = 2
(b,A,a,B) = 3-1 = 2
(b,b,A,a)
(b,b,A,a) 
(b,b,A,a)
(b,b,A,a)

Now we can count how many times we have at least a 'b' after any previous 'a', here 20, and we can calculate the average of these distances.
averagedistance = 30/20 = 1.5
What is the general formula for any Na and Nb?
I have only been able to calculate it (simulating numbers) for
Na=1 -> averagedistance= 1
or
Nb=1 -> averagedistance=((Na+1)/2)
but not a general formula.
and I think the complete solution has a factor Na!Nb!/(NaNb)!  and something else.
 [/INST] Let $\mathbf X$ be the distance we want.
Then there are $\binom{N_a+N_b}{N_b}$ ways to choose a permutation of the as and bs to consider. Of them, $\binom{N_a+N_b}{N_b}-1$ have an a followed by a b at some point.
Among them, there are $\binom{N_a + N_b-k+1}{N_b}-1$ ways to choose a permutation in which $\mathbf X \ge k$, because to get such a permutation, we can take any permutation of $N_a-k+1$ as and $N_b$ bs (except for the one we're excluding) then replace the first a we see by a block (a,a,...,a) of length $k$. This is a bijection.
Therefore we have
$$
   \mathbb E[\mathbf X] = \sum_{k=1}^{N_a} \Pr[\mathbf X \ge k] = \sum_{k=1}^{N_a} \frac{\binom{N_a + N_b - k +1}{N_b}-1}{\binom{N_a + N_b}{N_b}-1}.
$$
To simplify the sum, set $j = N_a - k + 1$. Then we have
$$
   \mathbb E[\mathbf X] = \frac1{\binom{N_a+N_b}{N_b}-1} \sum_{j=1}^{N_a} \binom{N_b+j}{N_b} - \frac{N_a}{\binom{N_a+N_b}{N_b}-1}= \frac{\binom{N_a+N_b+1}{N_b+1} - N_a - 1}{\binom{N_a+N_b}{N_b}-1} 
$$
by the hockey-stick identity.
</s>