Rep-string: Difference between revisions

Added solution for Action!
(Add Modula-2)
(Added solution for Action!)
Line 67:
'00' has reps [0]
'1' has reps []
</pre>
 
=={{header|Action!}}==
<lang Action!>BYTE FUNC IsCycle(CHAR ARRAY s,sub)
BYTE i,j,count
 
IF sub(0)=0 OR s(0)<sub(0) THEN
RETURN (0)
FI
 
j=1 count=0
FOR i=1 TO s(0)
DO
IF s(i)#sub(j) THEN
RETURN (0)
FI
j==+1
IF j>sub(0) THEN
j=1 count==+1
FI
OD
IF count>1 THEN
RETURN (1)
FI
RETURN (0)
 
PROC Test(CHAR ARRAY s)
CHAR ARRAY sub
BYTE len,count
 
PrintF("%S -> ",s)
count=0
FOR len=1 TO s(0)-1
DO
SCopyS(sub,s,1,len)
IF IsCycle(s,sub) THEN
IF count>0 THEN
Print(", ")
FI
Print(sub)
count==+1
FI
OD
IF count=0 THEN
Print("none")
FI
PutE()
RETURN
 
PROC Main()
Test("1001110011")
Test("1110111011")
Test("0010010010")
Test("1010101010")
Test("1111111111")
Test("0100101101")
Test("0100100")
Test("101")
Test("11")
Test("00")
Test("1")
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Rep-string.png Screenshot from Atari 8-bit computer]
<pre>
1001110011 -> 10011
1110111011 -> 1110
0010010010 -> 001
1010101010 -> 10, 1010
1111111111 -> 1, 11, 111, 1111, 11111
0100101101 -> none
0100100 -> 010
101 -> none
11 -> 1
00 -> 0
1 -> none
</pre>
 
Anonymous user