RosettaCodeData/Task/Rep-string/00DESCRIPTION

29 lines
1.3 KiB
Text
Raw Permalink Normal View History

2015-02-20 09:02:09 -05:00
Given a series of ones and zeroes in a string, define a repeated string or ''rep-string'' as a string which is created by repeating a substring of the ''first'' N characters of the string ''truncated on the right to the length of the input string, and in which the substring appears repeated at least twice in the original''.
2017-09-23 10:01:46 +02:00
For example, the string '''10011001100''' is a rep-string as the leftmost four characters of '''1001''' are repeated three times and truncated on the right to give the original string.
2015-02-20 09:02:09 -05:00
2017-09-23 10:01:46 +02:00
Note that the requirement for having the repeat occur two or more times means that the repeating unit is ''never'' longer than half the length of the input string.
2015-02-20 09:02:09 -05:00
2016-12-05 22:15:40 +01:00
;Task:
* Write a function/subroutine/method/... that takes a string and returns an indication of if it is a rep-string and the repeated string.   (Either the string that is repeated, or the number of repeated characters would suffice).
2015-02-20 09:02:09 -05:00
* There may be multiple sub-strings that make a string a rep-string - in that case an indication of all, or the longest, or the shortest would suffice.
* Use the function to indicate the repeating substring if any, in the following:
2016-12-05 22:15:40 +01:00
<dl><dd>
<pre>
1001110011
1110111011
0010010010
1010101010
1111111111
0100101101
0100100
101
11
00
1
</pre>
</dl>
2015-02-20 09:02:09 -05:00
* Show your output on this page.
2016-12-05 22:15:40 +01:00
<br><br>