Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
21
Task/Rep-string/Forth/rep-string-1.fth
Normal file
21
Task/Rep-string/Forth/rep-string-1.fth
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
: rep-string ( caddr1 u1 -- caddr2 u2 ) \ u2=0: not a rep-string
|
||||
2dup dup >r r@ 2/ /string
|
||||
begin 2over 2over string-prefix? 0= over r@ < and while -1 /string repeat
|
||||
r> swap - >r 2drop r> ;
|
||||
|
||||
: test ( caddr u -- )
|
||||
2dup type ." has "
|
||||
rep-string ?dup 0= if drop ." no " else type ." as " then
|
||||
." repeating substring" cr ;
|
||||
: tests
|
||||
s" 1001110011" test
|
||||
s" 1110111011" test
|
||||
s" 0010010010" test
|
||||
s" 1010101010" test
|
||||
s" 1111111111" test
|
||||
s" 0100101101" test
|
||||
s" 0100100" test
|
||||
s" 101" test
|
||||
s" 11" test
|
||||
s" 00" test
|
||||
s" 1" test ;
|
||||
13
Task/Rep-string/Forth/rep-string-2.fth
Normal file
13
Task/Rep-string/Forth/rep-string-2.fth
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
cr tests
|
||||
1001110011 has 10011 as repeating substring
|
||||
1110111011 has 1110 as repeating substring
|
||||
0010010010 has 001 as repeating substring
|
||||
1010101010 has 1010 as repeating substring
|
||||
1111111111 has 11111 as repeating substring
|
||||
0100101101 has no repeating substring
|
||||
0100100 has 010 as repeating substring
|
||||
101 has no repeating substring
|
||||
11 has 1 as repeating substring
|
||||
00 has 0 as repeating substring
|
||||
1 has no repeating substring
|
||||
ok
|
||||
34
Task/Rep-string/Julia/rep-string.julia
Normal file
34
Task/Rep-string/Julia/rep-string.julia
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
function list_reps{T<:String}(r::T)
|
||||
n = length(r)
|
||||
replst = T[]
|
||||
for m in 1:n>>1
|
||||
s = r[1:chr2ind(r,m)]
|
||||
(s^(div(n,m)+1))[1:chr2ind(r,n)] == r || continue
|
||||
push!(replst, s)
|
||||
end
|
||||
return replst
|
||||
end
|
||||
|
||||
tests = {"1001110011",
|
||||
"1110111011",
|
||||
"0010010010",
|
||||
"1010101010",
|
||||
"1111111111",
|
||||
"0100101101",
|
||||
"0100100",
|
||||
"101",
|
||||
"11",
|
||||
"00",
|
||||
"1",
|
||||
"\u2200\u2203\u2200\u2203\u2200\u2203\u2200\u2203"}
|
||||
|
||||
for r in tests
|
||||
replst = list_reps(r)
|
||||
rlen = length(replst)
|
||||
print(@sprintf(" %s ", r))
|
||||
if rlen == 0
|
||||
println("is not a rep-string.")
|
||||
else
|
||||
println("is a rep-string of ", join(replst, ", "), ".")
|
||||
end
|
||||
end
|
||||
62
Task/Rep-string/Objeck/rep-string.objeck
Normal file
62
Task/Rep-string/Objeck/rep-string.objeck
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
class RepString {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
strings := ["1001110011", "1110111011", "0010010010", "1111111111",
|
||||
"0100101101", "0100100", "101", "11", "00", "1"];
|
||||
each(i : strings) {
|
||||
string := strings[i];
|
||||
repstring := RepString(string);
|
||||
if(repstring->Size() > 0) {
|
||||
"\"{$string}\" = rep-string \"{$repstring}\""->PrintLine();
|
||||
}
|
||||
else {
|
||||
"\"{$string}\" = not a rep-string"->PrintLine();
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function : RepString(string : String) ~ String {
|
||||
offset := string->Size() / 2;
|
||||
|
||||
while(offset > 0) {
|
||||
left := string->SubString(offset);
|
||||
right := string->SubString(left->Size(),left->Size());
|
||||
if(left->Equals(right)) {
|
||||
if(ValidateMatch(left, string)) {
|
||||
return left;
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
};
|
||||
};
|
||||
|
||||
offset--;
|
||||
};
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
function : ValidateMatch(left : String, string : String) ~ Bool {
|
||||
parts := string->Size() / left->Size();
|
||||
tail := string->Size() % left->Size() <> 0;
|
||||
|
||||
for(i := 1; i < parts; i+=1;) {
|
||||
offset := i * left->Size();
|
||||
right := string->SubString(offset, left->Size());
|
||||
if(<>left->Equals(right)) {
|
||||
return false;
|
||||
};
|
||||
};
|
||||
|
||||
if(tail) {
|
||||
offset := parts * left->Size();
|
||||
right := string->SubString(offset, string->Size() - offset);
|
||||
each(i : right) {
|
||||
if(left->Get(i) <> right->Get(i)) {
|
||||
return false;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
22
Task/Rep-string/PureBasic/rep-string.purebasic
Normal file
22
Task/Rep-string/PureBasic/rep-string.purebasic
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
a$="1001110011"+#CRLF$+"1110111011"+#CRLF$+"0010010010"+#CRLF$+"1010101010"+#CRLF$+"1111111111"+#CRLF$+
|
||||
"0100101101"+#CRLF$+"0100100" +#CRLF$+"101" +#CRLF$+"11" +#CRLF$+"00" +#CRLF$+
|
||||
"1" +#CRLF$
|
||||
|
||||
Define.i : OpenConsole()
|
||||
|
||||
Procedure isRepStr(s1$,s2$)
|
||||
If Int(Len(s1$)/Len(s2$))>=2 : ProcedureReturn isRepStr(s1$,s2$+s2$) : EndIf
|
||||
If Len(s1$)>Len(s2$) : ProcedureReturn isRepStr(s1$,s2$+Left(s2$,Len(s1$)%Len(s2$))) : EndIf
|
||||
If s1$=s2$ : ProcedureReturn #True : Else : ProcedureReturn #False : EndIf
|
||||
EndProcedure
|
||||
|
||||
For k=1 To CountString(a$,#CRLF$)
|
||||
s1$=StringField(a$,k,#CRLF$) : s2$=Left(s1$,Len(s1$)/2)
|
||||
While Len(s2$)
|
||||
r=isRepStr(s1$,s2$)
|
||||
If Not r : s2$=Left(s2$,Len(s2$)-1) : Else : Break : EndIf
|
||||
Wend
|
||||
If Len(s2$) And r : PrintN(LSet(s1$,15,Chr(32))+#TAB$+"longest sequence: "+s2$) : EndIf
|
||||
If Not Len(s2$) : PrintN(LSet(s1$,15,Chr(32))+#TAB$+"found nothing.") : EndIf
|
||||
Next
|
||||
Input()
|
||||
|
|
@ -1,13 +1,17 @@
|
|||
/*REXX pgm determines if a str is a repStr, returns minimum len. repStr.*/
|
||||
s=1001110011 1110111011 0010010010 1010101010 1111111111 0100101101 0100100 101 11 00 1
|
||||
/* [↑] a list of binary strings.*/
|
||||
do k=1 for words(s); _=word(s,k) /*process all the binary strings.*/
|
||||
say right(_,25) repString(_) /*show the original & the result.*/
|
||||
end /*k*/ /* [↑] "result" may be negatory.*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*───────────────────────────────────REPSTRING subroutine───────────────*/
|
||||
repString: procedure; parse arg x; L=length(x); r@= ' rep string='
|
||||
do j=1 for L-1 while j<=L%2; p=left(x,j) /*WHILE tests max*/
|
||||
if left(copies(p,L),L)==x then return r@ left(p,15) '[length' j"]"
|
||||
end /*j*/ /* [↑] we have found a repString*/
|
||||
return ' (no repetitions)' /*(sigh)∙∙∙ a failure to find rep*/
|
||||
/*REXX pgm determines if a string is a repString, returns min. length repStr. */
|
||||
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)
|
||||
if \datatype(x,'B') then return " ***error!*** string isn't a binary string."
|
||||
|
||||
do j=1 for L-1 while j<=L%2; $=left(x,j); $$=copies($,L)
|
||||
if left($$,L)==x then return ' rep string=' left($,15) '[length' j"]"
|
||||
end /*j*/ /* [↑] we have found a good repString.*/
|
||||
|
||||
return ' (no repetitions)' /*(sigh)··· a failure to find repString*/
|
||||
|
|
|
|||
37
Task/Rep-string/VBScript/rep-string.vb
Normal file
37
Task/Rep-string/VBScript/rep-string.vb
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
Function rep_string(s)
|
||||
max_len = Int(Len(s)/2)
|
||||
tmp = ""
|
||||
If max_len = 0 Then
|
||||
rep_string = "No Repeating String"
|
||||
Exit Function
|
||||
End If
|
||||
For i = 1 To max_len
|
||||
If InStr(i+1,s,tmp & Mid(s,i,1))Then
|
||||
tmp = tmp & Mid(s,i,1)
|
||||
Else
|
||||
Exit For
|
||||
End If
|
||||
Next
|
||||
Do While Len(tmp) > 0
|
||||
If Mid(s,Len(tmp)+1,Len(tmp)) = tmp Then
|
||||
rep_string = tmp
|
||||
Exit Do
|
||||
Else
|
||||
tmp = Mid(tmp,1,Len(tmp)-1)
|
||||
End If
|
||||
Loop
|
||||
If Len(tmp) > 0 Then
|
||||
rep_string = tmp
|
||||
Else
|
||||
rep_string = "No Repeating String"
|
||||
End If
|
||||
End Function
|
||||
|
||||
'testing the function
|
||||
arr = Array("1001110011","1110111011","0010010010","1010101010",_
|
||||
"1111111111","0100101101","0100100","101","11","00","1")
|
||||
|
||||
For n = 0 To UBound(arr)
|
||||
WScript.StdOut.Write arr(n) & ": " & rep_string(arr(n))
|
||||
WScript.StdOut.WriteLine
|
||||
Next
|
||||
Loading…
Add table
Add a link
Reference in a new issue