My first threaded functional version uses 34 cycles ... % is count as a cycle as well
I have some trick in sleeve ... not working in java version, but getting under 27 ?!
OK, I am on 33 now. And now on 32.
Codding in excell is more convenienet than in notepad ...
I have finished SuperHack debugger in Excell VBA, it helps in debugging, but not producing codding ideas.
(32 works for inputs of length upto 108)
I could probably evolve to 31, but I should make higher changes to reach required 29.
Already on 30

... works for inputs of length upto 112 ... and now till 120 and now 122 ... 124

I had to add several blank lines to my code

And I have 29 ... upto 96
So finally on 29,117 ... and the input length could be prolonged a bit.
Oops php implementation differs from what I have expected

... back to codding
... no that was just wrongly sent solution...