It is a good challenge, thank you.
Are we allowed to use any other variables at all?
I can figure out the majority of the approach, but I have yet to work out how to make it either work on every string (I can quite easily make it work by making it break for special case strings), or without an extra, non-counter variable (which is also easy). Now just to figure out a way without an extra variable and make it work with all strings. Hmmmmm.