Rep-string: Difference between revisions
Content deleted Content added
Walterpachl (talk | contribs) REXX added |
Add NetRexx implementation |
||
Line 17: | Line 17: | ||
'1'</pre> |
'1'</pre> |
||
* Show your output on this page. |
* Show your output on this page. |
||
=={{header|NetRexx}}== |
|||
{{trans|REXX}} |
|||
<lang NetRexx>/* NetRexx */ |
|||
options replace format comments java crossref symbols nobinary |
|||
/* REXX *************************************************************** |
|||
* 11.05.2013 Walter Pachl |
|||
**********************************************************************/ |
|||
runSample(arg) |
|||
return |
|||
method repstring(Arg) public static |
|||
Parse Arg s |
|||
maxlen = (''''s'''').length.max(20) |
|||
sq=(''''s'''').right(maxlen) |
|||
n=s.length() |
|||
Loop l=s.length()%2 to 1 By -1 |
|||
If s.substr(l+1,l)=s.left(l) Then Leave |
|||
End |
|||
If l>0 Then Do |
|||
rep_str=s.left(l) |
|||
Loop i=1 By 1 |
|||
If s.substr(i*l+1,l)<>rep_str Then |
|||
Leave |
|||
End |
|||
If rep_str.copies(n).left(s.length())=s Then |
|||
Say sq 'has a repetition length of' rep_str.length() 'i.e. '''rep_str'''' |
|||
Else |
|||
Say sq 'is not a repeated string' |
|||
End |
|||
Else |
|||
Say sq 'is not a repeated string' |
|||
Return |
|||
method runSample(arg) public static |
|||
parse arg samples |
|||
if samples = '' then - |
|||
samples = - |
|||
'1001110011' - |
|||
'1110111011' - |
|||
'0010010010' - |
|||
'1010101010' - |
|||
'1111111111' - |
|||
'0100101101' - |
|||
'0100100' - |
|||
'101' - |
|||
'1' |
|||
loop w_ = 1 to samples.words() |
|||
repstring(samples.word(w_)) |
|||
end |
|||
return |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
'1001110011' has a repetition length of 5 i.e. '10011' |
|||
'1110111011' has a repetition length of 4 i.e. '1110' |
|||
'0010010010' has a repetition length of 3 i.e. '001' |
|||
'1010101010' has a repetition length of 4 i.e. '1010' |
|||
'1111111111' has a repetition length of 5 i.e. '11111' |
|||
'0100101101' is not a repeated string |
|||
'0100100' has a repetition length of 3 i.e. '010' |
|||
'101' is not a repeated string |
|||
'1' is not a repeated string |
|||
</pre> |
|||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |