Rep-string: Difference between revisions

Content added Content deleted
m (added whitespace before the TOC (table of contents), added other whitespace to the task's preamble.)
Line 2: Line 2:
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''.
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''.


For example, the string <code>'10011001100'</code> is a rep-string as the leftmost four characters of <code>'1001'</code> are repeated three times and truncated on the right to give the original string.
For example, the string &nbsp; &nbsp; '''10011001100''' &nbsp; &nbsp; is a rep-string as the leftmost four characters of &nbsp; &nbsp; '''1001''' &nbsp; &nbsp; are repeated three times and truncated on the right to give the original string.


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.
Note that the requirement for having the repeat occur two or more times means that the repeating unit is &nbsp; ''never'' &nbsp; longer than half the length of the input string.



The task is to:
;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).
* Write a function/subroutine/method/... that takes a string and returns an indication of if it is a rep-string and the repeated string. &nbsp; (Either the string that is repeated, or the number of repeated characters would suffice).
* 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.
* 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:
* Use the function to indicate the repeating substring if any, in the following:
<dl><dd><pre>'1001110011'
<dl><dd>
<pre>
'1110111011'
1001110011
'0010010010'
1110111011
'1010101010'
0010010010
'1111111111'
1010101010
'0100101101'
1111111111
'0100100'
0100101101
'101'
0100100
'11'
101
'00'
11
'1'</pre></dl>
00
1
</pre>
</dl>
* Show your output on this page.
* Show your output on this page.
<br><br>


=={{header|Ada}}==
=={{header|Ada}}==