8 coins are in a row and numbered from left to right.
For each turn, we count number of heads. If see k heads among these 8 coins, we flip the k-th coin (H to T, vice versa).
We stop until we see 8 tails and no heads.
What's the maximal number of turns until we stop?
My thoughts: say it's all tails first and the 8th one is head, then we flip from 1 to 7, change them all to heads. Then we change them back to tails. But how do I prove this is maximum?
My thoughts 2: TTTTHHHH will take 36 flips apparently
Best Answer
This is actually interesting.
Let's say there are $n$ coins, and we want to find the maximum flips.
It turns out that,
In both cases, the maximun number of flips is $n(n+1)/2$, and the configuration attaining the max is unique.
I'll leave the proof to others, because it's time for bed...
Seems nobody else wants to give a proof ...
OK here we go.
Let $M(n)$ be the maximum number of flips among all configurations of $n$ coins. For such a configuration, there are two possibilities:
The $n$-th coin is
T
. Then the $n$-th coin will always remainT
, until the end of the game. Hence it is essentially a game with $n - 1$ coins and the maximum number of flips is no more than $M(n - 1)$.The $n$-th coin is
H
. Then the $n$-th coin will still remainH
, until the configurationHH...H
is reached. After that, it's easy to see that $n$ more flips leads to the final configurationTT...T
.Therefore it suffices to consider the number of flips until the configuration
HH...H
.Now we reindex the coins: previously they were indexed $1, 2, \dotsc, n$, and now we index them as $n - 1, \dotsc, 1, 0$. Under this new index system, the rule of flipping becomes: if there are $k$ tails among the first $n - 1$ coins, then we flip the coin with new index $k$. The procedure continues until all the first $n - 1$ coins are
H
, i.e. we reach the configurationHH...H
.This is then exactly the same game with $n - 1$ coins, and with heads and tails exchanged. Thus the maximum number of flips until the configuration
HH...H
is $M(n - 1)$, and hence the total maximum number of flips (until the configurationTT...T
) is $M(n - 1) + n$.Combining 1. and 2., we get $M(n) = M(n - 1) + n$, and the maximum is attained only when the last coin is
H
, and the first $n - 1$ coins attain the maximum for the game with $n - 1$ coins, withH
andT
switched and order inversed.By induction on $n$, this proves exactly our claims.