Rep-string: Difference between revisions

Updated for Nim 1.4: added missing parameter type; replaced ".. <" with "..< ".
(Added 11l)
(Updated for Nim 1.4: added missing parameter type; replaced ".. <" with "..< ".)
Line 2,018:
<lang nim>import strutils
 
proc isRepeated(text: string): int =
for x in countdown(text.len div 2, 0):
if text.startsWith(text[x..text.high]): return x
Line 2,037:
let ln = isRepeated(line)
echo "'", line, "' has a repetition length of ", ln, " i.e ",
(if ln > 0: "'" & line[0 .. < ln] & "'" else: "*not* a rep-string")</lang>
{{Out}}
<pre>'1001110011' has a repetition length of 5 i.e '10011'
Anonymous user