Solution:
Let E0 be the expected number of flips needed. Let E1 be the expected number more of flips needed if the first flip landed on H. Let E2 be the expected number more if the first two landed on HM. In general, let Ek be the expected number more of flips needed if the first k flips landed on the first k values of the sequence HMMTHMMT...HMMT.
We have
Ei={1+31Ei+1+31E1+31E01+31Ei+1+32E0i≡0i≡0(mod4)(mod4)
Using this relation for i=0 gives us E1=E0−3. Let Fi=3i1Ei. By simple algebraic manipulations we have
Fi+1−Fi={−3i+12⋅E0−3i1−3i+12⋅E0i≡0i≡0(mod4)(mod4)
We clearly have F2016⋅4=0 and F0=E0. So adding up the above relations for i=0 to i=2016⋅4−1 gives
−E0=−2E0i=1∑2016⋅43i1−k=0∑201534k1=E0(32016⋅41−1)−81801−32016⋅41
so E0=8038068−81.