For $n = 2$, the solution is trivial - you flip both coins heads-up for the first two days, and leave.
For $n = 3$, you leave the first coin alone, leaving Satan with TTH. But no matter whether Satan flips this coin or leaves it alone, you can flip all the T's in a row afterwards, so you win.
For $n = 4$, you leave the first coin alone, leaving Satan with TTHH. Regardless of how Satan flips these two coins, in all four cases you're left with a string of 2, 3, or 4 consecutive T's, so you can flip all of them and win.
(In the case of flipping only the second one, you're left with THTT, but just leave those two alone and no matter what Satan flips, you can flip all of them the second time around.)
$n = 5$ is the first interesting case. Then, if Satan flips only the second H out of three after you leave the first coin alone, you're left with HTHTT. If you leave this alone, then Satan will also leave it alone, and you'll be stuck in a loop forever. So the only thing to do is to either flip the solitary T, or flip one or both of the two consecutive T's.
If you flip one of the two consecutive T's, you've left Satan with either HTHTH or THHTH depending on which one you flipped. Satan can just leave this alone, which means you're stuck in an infinite loop until you decide to flip one of the others.
If you flip the first one, Satan's left with HHHTH. If he leaves this alone, then you flip the T and win. So he has to flip this H, leaving you with THHHT, back where you started.
If you flip the second one, Satan's left with HHTHH. But he can just leave the first H alone and flip the second one, leaving you back where you started as well.
If you flip the solitary T, then Satan's left with HHTTH. If he leaves this H alone, then you flip the T and win. So he has to flip the T, leaving you with THHTT. Just leave these two alone, leaving Satan with TTTHH and the same quandary he had in the $n = 4$ case.
In general, you want to leave Satan with a situation where all the T's are in a single bunch and a single H follows them. Then, he's forced to increase the length of the T chain by 1 (and thereby effectively reduce the number of coins in the game inductively), and if you can keep doing that, then by induction you win.
For $n = 6$, Satan can flip one, the other, or both of the two coins not next to the existing T's, leaving you with one of HHTHTT, HTHHTT, or HTTHTT once you've gone a full revolution. In any case where Satan flips the coin right before the leftmost H, you leave them alone (and your first two T's) the first time around, and flip them all back to heads the second round, leaving Satan with HHHTTH and you winning.
So Satan has to flip the first coin only where he's left with HHTTHH and has the choice of flipping the T, which is the only nontrivial variation from $n = 5$.
Let's suppose he does this. Then you're left with HTHHTT, which, from above, is one of the winning strategies. So you win as well.
We still haven't deduced a general strategy yet, so let's continue with $n = 7$.
Satan can leave you with HTHTHTT this time, which circumvents the flipping-the-one-next-to-last rule described above since the first flipped T prevents Satan from being forced to flip the H immediately before the string of two T's. But in this case, if you flip the first solitary T the second time around, then Satan has to flip the next H, because if he leaves it alone, you can just flip the next T as well, leaving Satan with HHHHTTH and starting the $n = 6$ case. So he has to flip that H, leaving you with HTTHHTT the second time around. Then you simply flip the left sequence of T's and force the $n = 6$ case again.
But there is one wrinkle here. What if Satan flips to HHTHHTT, and you flip that T only for Satan to flip the H immediately afterwards (resulting in HTHHHTT) and then Satan flips the second H only, resulting in HTHTTHT on your turn? If you flip the T now, and then the next solitary T right afterward, Satan will just flip the next T again, returning you to HHTHHTT.
So, you just leave that second T alone for two days, and the HTHTHTT case plays out exactly as described in the first place.
At this point, we finally notice a pattern. You will always flip the series of T's immediately after your longest chain (which starts at length 2 and keeps growing until it's the entire string of coins), which forces Satan to flip the H immediately to the left of them in order to ward off defeat. And if Satan flips any of the H's beforehand, leave the rest of the T's alone and let it go around one more revolution.
This will always result in the set of stray T's moving left towards the end of your longest chain and merging together with other stray sets, or a set of new T's being created that will have to move left anyway, possibly creating an even longer chain in the process.
The longest Satan can drag the game out for when your longest chain is $m$ T's long (without making a longer chain in the process) is until the chain of $m$ T's is followed by a series of chains of $m$ T's each separated by a single H. At that point, any head Satan flips will automatically create a longer chain, so you can flip all the chains of $m$ T's, leaving Satan with the coin right before the last chain of $m$ T's which he must then extend to $m+1$.
And this way, you can always defeat Satan and escape from Hell.
Below is a program-like algorithm that you can follow, assuming that instead of moving coins to the left, you keep track of a cursor that moves to the left one space every day.
- Every day, the cursor moves left one space. If the cursor reaches the leftmost coin, it jumps back to the right.
- If you are on your rightmost set of consecutive T's, pass.
- If Satan has not flipped a coin yet since the cursor last jumped to the right and you are currently on a T, flip it. Otherwise, pass.
- If Satan flips the leftmost coin, move that coin to the rightmost position, keeping the cursor on it.
An example of the longest match for $n = 11$, to show how this algorithm might work:
HHHHHHHHHTT You leave the two T's alone, Satan flips coin 8.
HHHHHHHTHTT You flip the first T, forcing Satan to flip coin 7.
HHHHHHTHHTT You flip the first T, forcing Satan to flip coin 6.
HTHHHHHHHTT Satan flips coin 8 again, and you leave everything alone.
HTHHHHHTHTT You flip coin 8, and keep moving left until Satan reaches coin 4.
HTHTHHHHHTT Satan flips coin 8 again. This flipping coin 8 and moving to the left continues until all the even-numbered slots are occupied.
HTHTHTHTHTT You start flipping all the T's from coin 8 onward. If Satan flips any coins before that, stop and let the cursor wrap around again.
HTTHHHHTHTT This might happen. Then, Satan flips coin 8 and starts the above process all over.
HTTHTTHHHTT This might happen again.
HTTHTTHTHTT Satan flips coin 8 one last time, but he cannot dodge anymore. You leave the coins alone for one more iteration.
THHHHHHHHTT You flip all groups of coins, leaving Satan with no choice but to flip coin 1.
HHHHHHHHTTT The frame of reference of the coins move forward one space.
HHHHHHTHTTT Satan starts with coin 7 this time.
HTHTHTHHTTT Chains of length 1.
HTHTHTTHTTT Satan flips coin 7. You leave all the other coins alone.
HTTHHHHHTTT Satan is forced to do this again.
HTTHHHTHTTT Same process as before.
HTTHTTHHTTT Chains of length 2. You flip the first chain, Satan flips coin 4.
HTTTHHHHTTT First chain of length 3. Satan flips coin 7 again, and the process continues.
HTTTHTTHTTT In 3 moves, Satan exhausts the chain of length 3. You flip all sequences of coins to the left of your first chain.
THHHHHHHTTT Again, Satan has no choice but to flip coin 1. The chain extends by length 1 again.
It turns out that the number of moves required to force a win grows exponentially compared to the number of coins in a row.