In college I came across this and I couldn't seem to find an answer for it yet (it's not a homework, just a riddle). Let's say you have input in Turing machine:
01001101 (8 bit sequence)
How do you count the largest subsequence of ones in such an input and get correct output 2#01001101? (2 because there are two ones near each other).
I can correctly count and write the first subsequence and so I have this on tape :
1#01001101
but then I have no idea how to count other subsequences of ones and not overwrite the result by a lower number (of the last subsequence). Do you have any ideas?
edit: Only one scratch tape to work on.
This is conceptually easy, but quite cumbersome to program (like anything non-trivial on a Turing machine). Here's an outline of an algorithm:
This is really a translation of the straightforward algorithm:
where the variables are replaced by scratch tapes.