I have this question for a practice problem set and I am trying to figure out a way to solve this logically. It is simple to solve iteratively through code, but I am having trouble deriving a formula to solve this.
I know that there are $2^x$ possible combinations based on x coin flips, but I can't figure out a method to extract all combinations that contain either an HH or HT.
Any thoughts? Appreciate the help.
Applying stars and bars it can be found that:
$$2^x-\sum_{0\leq k\leq\frac12x+\frac12}\binom{x+1-k}k$$combinations will contain substring "HH".
Unfortunately I cannot find a closed form for $\sum_{0\leq k\leq\frac12x+\frac12}\binom{x+1-k}k$ which of course is the number of combinations that do not contain substring "HH".
The case of finding the same for substring "HT" is less difficult.
If e.g. $x=4$ then the following $4+1=5$ combinations do not contain substring "HT":
If writing from left to right the first "H" has been placed then only other "H"-s can follow.
This gives $$2^x-x-1$$possible combinations that contain substring "HT".