in reply to Re: Finding repeat sequences.
in thread Finding repeat sequences.
That's interesting...(not faint praise.). (I'm already thinking of optimisations; like build the longest repeat sequence and then use substr to get shorter versions.)
For example, given the input abcabca, it could be ... So the only interesting answer to return is the shortest possible one.
Hm. Damn you for making me think (again) at this time of night :)
There will always be at least one complete substring.
If there is more than 1 but less than 2, ie. 1 rep + 1 partial; (I believe) it will always be possible to determine the longest < length string match; because the residual always matches the length( residual ) first characters of the string.
So, if the string is 'abcabca'; the rep could be 'abcabc' or 'abc'. But if the rep consists entirely of an exact integer number of reps of a subsubstring, then the substring is that subsubstring and the string consists of rep*n(n>1) + a partial.
Thus, I believe that there is only ever one results.
It will be interesting to pitch your solution against DamianConway's regex and see how they compare. I simply have no feel for it; but it's a job for tomorrow.
Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Finding repeat sequences.
by hdb (Monsignor) on Jun 19, 2013 at 07:46 UTC |