# Expected value of coin flips

In regards to:
https://math.stackexchange.com/a/1584597/323580

Question:

I flip a fair coin independently 6 times. This gives me a sequence of heads and tails. For each consecutive 'HTH' in the sequence you win $5. So I define a random variable X to be the amount of dollars that I win. For example here is what$X=5$is:$THTHTT$, and$X=10$is:$THTHTH$. What is the best way to calculate the expected value of X? Accepted Answer: We use the method of indicator random variables, and solve the problem for$n$tosses. For$k=3$to$n$, let random variable$X_k$be$1$if there is an HTH sequence ending at the$k$-th toss, and let$X_k=0$otherwise. Then the amount$W$that we win is given by $$W=5(X_3+X_4+\cdots +X_n).$$ By the linearity of expectation we have $$E(W)=5E(X_3)+5E(X_4)+\cdots+5E(X_n).$$ We have$E(X_i)=\Pr(X_i=1)=\frac{1}{8}$, so$E(W)=\dfrac{5(n-2)}{8}$. Only minor modification is needed for a biased coin that has probability$p$of landing heads. André Nicolas (https://math.stackexchange.com/users/6312/andr%c3%a9-nicolas), Expected value of coin flip sequence, URL (version: 2015-12-21): https://math.stackexchange.com/q/1584597 This user has stated on his profile that he cannot answer questions about past posts: I am wondering why$Pr(X_i=1) = 1/8$? Since there are$6$coin flips, there are$2^6$possible outcomes. Did he calculate every single way there can be a sequence of$HTH$and divided by$2^6$to get$1/8$or is there an easier way? I believe there is an easier, more intuitive way, but I don't know how. What if I decided I wanted my indicator random variable to be$1$if$X_i, X_{i+1}, X_{i+2}$creates the sequence$HTH$respectively ($k = 1$to$4$inclusive)? • Since we specify the end toss, the event$X_i$consists of just 3 coin tosses (anything before these flips is fine), of which there are 8 outcomes and exactly one of them is$HTH$. – Countingstuff Apr 22 '18 at 16:12 ## 2 Answers Basically, it is simply$\frac18$of the sequences will be$HTH?????$so$P(X_3=1)=\frac18\frac18$of the sequences will be$?HTH????$so$P(X_4=1)=\frac18\frac18$of the sequences will be$??HTH???$so$P(X_5=1)=\frac18\frac18$of the sequences will be$???HTH??$so$P(X_6=1)=\frac18\frac18$of the sequences will be$????HTH?$so$P(X_7=1)=\frac18\frac18$of the sequences will be$?????HTH$so$P(X_8=1)=\frac18$Your suggested indexing simply lowers the indices by$2$. If you start with HTH, then the other three outcomes have 8 possibilities.$${HTH, HTT, HHT, HHH, TTH, TTT, THT, THH} So far we have$3$cases of$10$dollars and$5$cases of$5$dollars. That gives you$55$out of these$8$trials. Similarly see what happens if the first$HTH\$ starts with the second flip of the coin.

Continue with other cases and get the total money out of all 64 cases and divide the result by 64.