Toss a fair coin $n \ge 5$ times, and let $X$ be the number of occurrences of the pattern $HHH$ in the sequence of tosses. For example, if $n = 9$ and the outcome is $\omega = HHTHHHHTH$ then $X(\omega) = 2$. Compute E[$X$] and Var ($X$).
My idea so far is to start with $n=5$, where there are three possible outcomes that give us at least three consecutive heads, namely $HHHTT,THHHT,TTHHH,HHHHT,THHHH,HHHHH$, in the first three outcomes we get $X(\omega)=1$, in the third and fourth outcomes we get $X(\omega)=2$, and for the final outcome we get $X(\omega)=3$.
When we move on to $n=6$ and assess all outcomes we get $4$ occurrences of $X(\omega)=1$, $3$ occurrences of $X(\omega)=2$, $2$ occurrences of $X(\omega)=3$, and $1$ occurrence of $X(\omega)=4$.
I don't know exactly what to do with this information or if I'm going in the right direction, but any help is appreciated.
Indicator random variables are your friend here. There are $n-2$ windows of three tosses in the sequence, and each window has a $\frac18$ chance to come up $HHH$ (i.e. we consider each window as a random variable, and these add to make $X$). Therefore the expected value of $X$ is $\frac{n-2}8$.
For the variance of $X$ we sum up the following:
Thus the variance of $X$ is $$\frac1{64}(7(n-2)+6(n-3)+2(n-4))=\frac{15n-40}{64}$$