Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
52
Task/Rep-string/REXX/rep-string-1.rexx
Normal file
52
Task/Rep-string/REXX/rep-string-1.rexx
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* REXX ***************************************************************
|
||||
* 11.05.2013 Walter Pachl
|
||||
* 14.05.2013 Walter Pachl extend to show additional rep-strings
|
||||
**********************************************************************/
|
||||
Call repstring '1001110011'
|
||||
Call repstring '1110111011'
|
||||
Call repstring '0010010010'
|
||||
Call repstring '1010101010'
|
||||
Call repstring '1111111111'
|
||||
Call repstring '0100101101'
|
||||
Call repstring '0100100'
|
||||
Call repstring '101'
|
||||
Call repstring '11'
|
||||
Call repstring '00'
|
||||
Call repstring '1'
|
||||
Exit
|
||||
|
||||
repstring:
|
||||
Parse Arg s
|
||||
sq=''''s''''
|
||||
n=length(s)
|
||||
Do l=length(s)%2 to 1 By -1
|
||||
If substr(s,l+1,l)=left(s,l) Then Leave
|
||||
End
|
||||
If l>0 Then Do
|
||||
rep_str=left(s,l)
|
||||
Do i=1 By 1
|
||||
If substr(s,i*l+1,l)<>rep_str Then
|
||||
Leave
|
||||
End
|
||||
If left(copies(rep_str,n),length(s))=s Then Do
|
||||
Call show_rep rep_str /* show result */
|
||||
Do i=length(rep_str)-1 To 1 By -1 /* look for shorter rep_str-s */
|
||||
rep_str=left(s,i)
|
||||
If left(copies(rep_str,n),length(s))=s Then
|
||||
Call show_rep rep_str
|
||||
End
|
||||
End
|
||||
Else
|
||||
Call show_norep
|
||||
End
|
||||
Else
|
||||
Call show_norep
|
||||
Return
|
||||
|
||||
show_rep:
|
||||
Parse Arg rs
|
||||
Say right(sq,12) 'has a repetition length of' length(rs) 'i.e.' ''''rs''''
|
||||
Return
|
||||
show_norep:
|
||||
Say right(sq,12) 'is not a repeated string'
|
||||
Return
|
||||
16
Task/Rep-string/REXX/rep-string-2.rexx
Normal file
16
Task/Rep-string/REXX/rep-string-2.rexx
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/*REXX pgm determines if a string is a repString, it returns minimum length repString.*/
|
||||
parse arg s /*get optional strings from the C.L. */
|
||||
if s='' then s=1001110011 1110111011 0010010010 1010101010 1111111111 0100101101 0100100 101 11 00 1 45
|
||||
/* [↑] S not specified? Use defaults*/
|
||||
do k=1 for words(s); _=word(s,k); w=length(_) /*process binary strings. */
|
||||
say right(_,max(25,w)) repString(_) /*show repString & result.*/
|
||||
end /*k*/ /* [↑] the "result" may be negatory.*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
repString: procedure; parse arg x; L=length(x); @rep=' rep string='
|
||||
if \datatype(x,'B') then return " ***error*** string isn't a binary string."
|
||||
h=L%2
|
||||
do j=1 for L-1 while j<=h; $=left(x,j); $$=copies($,L)
|
||||
if left($$,L)==x then return @rep left($,15) "[length" j']'
|
||||
end /*j*/ /* [↑] we have found a good repString.*/
|
||||
return ' (no repetitions)' /*failure to find repString.*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue