The period of a pline wis any natural number psuch that w[i]=w[i+p]when both sides of this equation are defined. Denote by the per(w)size of the smallest period w. We say that the string wis equal to periodic iff per(w) <= |w|/2.
So unofficially a periodic line is just a line that consists of a prefix repeated at least twice. The only complication is that at the end of the line we do not need a full copy of the prefix.
For example, consider a line x = abcab. per(abcab) = 3like x[1] = x[1+3] = a, x[2]=x[2+3] = band there is no shorter period. Therefore, the row is abcabnot periodic. However, the string ababais periodic as per(ababa) = 2.
As additional examples abcabca, ababababaand abcabcabcare also periodic.
Is there a regular expression to determine if a string is periodic or not?
Actually, I don't mind what the taste of the regular expression tastes like, but if it matters, all that Python supports re.
source
share