I want to determine an unknown pattern in a string such as,
s=112468112468112468112468112468.
So in this string, we can clearly see that 112468 is the repeating pattern. I searched on google quite a bit for finding some algorithms to help me, but I could only see ones which find a given pattern in a string such as Boyer-Moore algorithm etc.
What I do now to find these repeating unknown pattern is that,
for(i=0;i<Length of String;i++)
{
for(j=i+1;j<Length of String;j++)
{
if(s[i]==s[j] && s[i+1]==s[j+1] && s[i+2]==s[j+2] && s[i+3]==s[j+3])
{
patternlength=j-i;
for(k=i;k<j;k++)
{
pattern[k]=s[i+k]
}
}
}
}
Although this works for the given string by using a comparison window of 4 literals, it may very well not work for some other string. Does anybody know a better solution to this.
Thanks