TITLE: Arrangement of dimes to bring all heads
QUESTION [5 upvotes]: Consider an arrangement of n dimes in a straight line. A move consists of taking a dime and turning it over (from head to tail or vice versa) and of doing the same to each of its neighbors. If the dime is at the end of the line, then it will have only one neighbor. For example, if the arrangement is HHTH and you choose the second dime, then your move would result in TTHH. The general question is this: Given any arrangement of n dimes, is it possible to find a sequence of moves to bring it to all heads?

REPLY [2 votes]: Thanks @saulspatz for the numerical evidence, without which I could not have found this proof:
For any length $k$, going from the left to the right in one pass, find the first T, flip it to H without affecting all the Hs to its left.  E.g. HHTTH -> HH(TTH) -> HH(HHT).  By doing so you are left with either all Hs (done) or all Hs except the rightmost position is T.  In the this latter case: 

if $k = 3n$, you have $3n-1$ Hs.  Go from right to left in one pass, flip non-overlapping sets of 3 coins to T, and the final set of 2 coins also to T.  Now you have all Ts.  Flip them all over to Hs, which is doable because $k=3n$.
if $k = 3n+1$, you have $3n$ Hs.  Do the same as above to get to all Ts.  Now flip them as $2 + 3 + 3 + \cdots + 3 + 2$ back to all Hs.

The above procedure constructively proves that the problem is solvable for all $k= 3n$ or $3n+1$.
To show that $k=3n+2$ is NOT solvable first observe that in any sequence of moves, if you make the same move, i.e. at a certain position $i$, twice, their effects cancel out, EVEN IF they were done at separate (discrete) time in the sequence.  Thus any move sequence (of any length) actually boils down to a subset of all possible moves.  There are $k$ possible moves, so there are only $2^k$ subsets.  For the problem to be solvable, each subset must have a DIFFERENT effect, since there are $2^k$ possible starting positions.  However, for $k=3n+2$, the moves $3 + \cdots + 3 + 2$ and the moves $2 + 3 + \cdots + 3$ have the same effect.  So the no. of all possible effects $< 2^k$ and some starting position must be unsolvable.  
ALTERNATE VIEW: The move at position $j$ ($1 \le j \le k$) can be modeled as a $k$-vector $v_j$ with $1$s at positions $j-1, j, j+1$ (ignore out of range entries) and $0$ everywhere else.  Then doing the $j$th move and then the $j_2$th move can be modeled as $v_j + v_{j_2}$ mod2, and doing a subset $M$ of moves can be modeled as $\sum_{j \in M} v_j$.  This suggests a matrix representation.  (Assume mod2 from now on.)
Let $A$ be the (tri-diagonal) $k \times k$ matrix where $A_{ij} = 1$ if $|i-j|\le 1$ and $0$ otherwise.  So a subset $M$ of moves can be represented as a $k$-vector $m$ where $m_j = 1$ if $j \in M$ and $0$ otherwise, and doing those moves have effect $A m$, i.e. the end result is flipping all positions $p$ where $[Am]_p = 1$.
Any given starting position can be represented by a $k$-vector $t$ where $t_j = 1$ if the $j$th position is T, and $0$ if it is H.  So solving $t$ means finding $m$ s.t. $t = Am$.  Thus, the problem is solvable for all $t$ iff $A$ has full rank, or equivalently, $det(A) \neq 0$.  Let $d_k$ be the determinant of the $k\times k$ version of the $A$ matrix.  From the structure of the tridiagonal matrices by looking at the minors, one can show $d_k = d_{k-1} + d_{k-2}$.  Staring from $d_2 = 0, d_3 = 1$ the rest of the sequences goes $1, 0, 1, 1, 0, 1, 1, 0, 1$ etc.  This again shows the problem is solvable (for all starting positions) iff $k = 3n$ or $3n+1$.
Further, for $k=3n+2$, while $A_{k \times k}$ does not have full rank, it contains $A_{(k-1)\times (k-1)}$ as a block, and the block has full rank, so $rank(A_{k \times k}) = k-1$.  Therefore, the number of solvable starting positions $=|range(A_{k \times k})| = 2^{k-1}$, i.e. exactly half the starting positions are solvable.
BTW here are $A^{-1}$ for $k=12$ and $13$, just for fun.  The $j$th column (or row) is how one would solve a single T at $j$.  The patterns are quite different for $3n$ and $3n+1$.
0 1 1 0 1 1 0 1 1 0 1 1
1 1 1 0 1 1 0 1 1 0 1 1
1 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 1 0 1 1 0 1 1
1 1 0 1 1 1 0 1 1 0 1 1
1 1 0 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 1 0 1 1
1 1 0 1 1 0 1 1 1 0 1 1
1 1 0 1 1 0 1 1 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 1
1 1 0 1 1 0 1 1 0 1 1 1
1 1 0 1 1 0 1 1 0 1 1 0

1 0 1 1 0 1 1 0 1 1 0 1 1
0 0 1 1 0 1 1 0 1 1 0 1 1
1 1 0 0 0 0 0 0 0 0 0 0 0
1 1 0 1 0 1 1 0 1 1 0 1 1
0 0 0 0 0 1 1 0 1 1 0 1 1
1 1 0 1 1 0 0 0 0 0 0 0 0
1 1 0 1 1 0 1 0 1 1 0 1 1
0 0 0 0 0 0 0 0 1 1 0 1 1
1 1 0 1 1 0 1 1 0 0 0 0 0
1 1 0 1 1 0 1 1 0 1 0 1 1
0 0 0 0 0 0 0 0 0 0 0 1 1
1 1 0 1 1 0 1 1 0 1 1 0 0
1 1 0 1 1 0 1 1 0 1 1 0 1