expectation of (largest) number of consecutives Go out from independent events $E_{1},E_{2},\ldots$ that can succeed
or fail. 
This with $p=P\left\{ E_{n}\text{ succeeds}\right\} $ for
each $n$. 
For $n=1,2,\ldots$ define $X_{n}$ as the largest number of consecutive
successes in the first $n$ events.
For instance if $n=6$ and we denote success by S and failure by F
then:
SSSSSF gives $X_{6}=5$
SSFSSF gives $X_{6}=2$
SSSFSF gives $X_{6}=3$
SSFSSS gives $X_{6}=3$
SFFFSF gives $X_{6}=1$
I am looking for an expression for $E\left[X_{n}\right]$. Uptil now
without succes. I would not be surprised if it turnes out to be 
a hard problem. Help, or reference to something that looks like it,
is welcome.
 A: Let $(M_n)$ denote the Markov chain starting from $M_0=0$ with transition probabilities $p(n,n+1)=p$ and $p(n,0)=1-p$ for every $n\geqslant0$. Then $M_n$ describes the length of the part before $n$ of the run of successes which includes time $n$. Hence there exists a run of $k$ or more successes included in the $n$th first results if and only if $T_k\leqslant n$ where $T_k=\inf\{n\geqslant0\mid M_n=k\}$, and
$$
E[X_n]=\sum_{k\geqslant1}P[X_n\geqslant k]=\sum_{k\geqslant1}P[T_k\leqslant n].
$$
The generating function $u_x(s)=E_x[s^{T_k}]$ of $T_k$ starting from $x$ successive successes is such that $u_x(s)=s(qu_0(s)+pu_{x+1}(s))$ for every $0\leqslant x\leqslant k-1$, where $q=1-p$ and $u_k(s)=1$.
Summing $p^xs^xu_x(s)-p^{x+1}s^{x+1}u_{x+1}(s)=p^xqs^{x+1}u_0(s)$ from $x=0$ to $x=k-1$ yields $u_0(s)-p^ks^k=qs(1+\cdots+(ps)^{k-1})u_0(s)$, that is,
$$
u_0(s)=\frac{(ps)^k}{1-qs(1-(ps)^k)/(1-ps)}=\frac{(ps)^k(1-ps)}{1-s+qs(ps)^k}.
$$
The $s^n$ term of $u_0(s)$ is $P[T_k=n]$.
Thus, exact formulas for $E[X_n]$ are not easy to write down. On the other hand, asymptotics are simpler since, when $n\to\infty$,
$$
E[X_n]\sim-\log n/\log p.
$$
