Expected no. of tosses before getting a sequence of 'x' heads and 'y' tails Recently I've been solving questions like "expected no. of trials before getting a particular sequence". The elegance of some of the solutions made me wonder whaich questions are solvable and which aren't.
Then I thought about this one: what would be the expected number of trials before getting a sequence of n heads followed by n tails?
In general, if you have two integers, x and y, what are the expected number of tosses before getting x continuous heads followed by y continuous tails? 
I'm not sure if this is solvable for a general x and y. But x=y=n seems more solvable than the former. 
My approach: 
Suppose A = expected no. of tosses to get x continuous heads, and B = expected no. of tosses before getting y continuous tails. 
Let P = probability of getting y continuous tails. 
Then A/P should give us the expected no. of tosses before getting x heads and y tails. 
Justification: Lets say there are n experiments, out of which k times you get y continuous tails. 
Now suppose you keep tossing coins to get 'x' continuous heads, for which you will do 'A' coin tosses. The moment you get 'x' continuous heads, you continue tossing coins for 'y' continuous tails. 
Suppose the event of tossing coins 'A' times is conducted n number of times. Then out of them, k events will also give you y consecutive tails after x consecutive heads. So on an average, after every n/k no. of such events you will have one such (x,y) event i.e. an event with x continuous heads and y continuous tails. 
Not sure of the answer, haven't seen this question anywhere.  
 A: Fix positive integers $x,y$.

For $0 \le m \le x+y$, let $e(m)$ be the expected number of tosses required to get an $H,\!T$-sequence of length $x+y$, comprised of $x$ heads, followed by $y$ tails, assuming the $m$ immediately preceding prior tosses match the initial $m$ terms of the target sequence.

Then for $0\le m \le x+y$, we get
$$
e(m)=
\begin{cases}
0&\;\;\;\text{if}\;\,m=x+y\\[4pt]
1+(\frac{1}{2})\,e(m+1)+(\frac{1}{2})\,e(0)&\;\;\;\text{if}\;\,0 \le m < x\\[4pt]
1+(\frac{1}{2})\,e(x+1)+(\frac{1}{2})\,e(x)&\;\;\;\text{if}\;\,m=x\\[4pt]
1+(\frac{1}{2})\,e(m+1)+(\frac{1}{2})\,e(1)&\;\;\;\text{if}\;\,x < m < x+y\\
\end{cases}
$$
which yields a system of $x+y+1$ linear equations, in $x+y+1$ unknowns.

Solving the system for $e(0)$, test data strongly suggests (but I don't have a proof) that the expected number of tosses required to get an $H,\!T$-sequence of length $x+y$, comprised of $x$ heads, followed by $y$ tails, is $2^{x+y}$.

Update:

The OP has now provided a link to a web article:

$\qquad$[randomprojection] -- Martingales & Coins - Waiting for Heads-Tails-Heads (2012)

$\qquad$https://tsourakakis.com/2012/01/01/waiting-for-heads-tails-heads/

which provides three different approaches for dealing with these kinds of problems.

The second approach is quite novel, and shows how to interpret the problem as a martingale.

Following that approach, the result $e(0)=2^{x+y}$ is immediate.

In particular, if $x=y=n$, we get $e(0)=4^n$.
