Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
31
Task/Rep-string/Ada/rep-string.adb
Normal file
31
Task/Rep-string/Ada/rep-string.adb
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
with Ada.Command_Line, Ada.Text_IO, Ada.Strings.Fixed;
|
||||
|
||||
procedure Rep_String is
|
||||
|
||||
function Find_Largest_Rep_String(S:String) return String is
|
||||
L: Natural := S'Length;
|
||||
begin
|
||||
for I in reverse 1 .. L/2 loop
|
||||
declare
|
||||
use Ada.Strings.Fixed;
|
||||
T: String := S(S'First .. S'First + I-1); -- the first I characters of S
|
||||
U: String := (1+(L/I)) * T; -- repeat T so often that U'Length >= L
|
||||
begin -- compare first L characers of U with S
|
||||
if U(U'First .. U'First + S'Length -1) = S then
|
||||
return T; -- T is a rep-string
|
||||
end if;
|
||||
end;
|
||||
end loop;
|
||||
return ""; -- no rep string;
|
||||
end Find_Largest_Rep_String;
|
||||
|
||||
X: String := Ada.Command_Line.Argument(1);
|
||||
Y: String := Find_Largest_Rep_String(X);
|
||||
|
||||
begin
|
||||
if Y="" then
|
||||
Ada.Text_IO.Put_Line("No rep-string for """ & X & """");
|
||||
else
|
||||
Ada.Text_IO.Put_Line("Longest rep-string for """& X &""": """& Y &"""");
|
||||
end if;
|
||||
end Rep_String;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
func$ repstr s$ .
|
||||
sl = len s$ div 2 + 1
|
||||
while sl > 1
|
||||
r$ = substr s$ sl 999
|
||||
r$ = substr s$ sl 99999
|
||||
if r$ = substr s$ 1 len r$
|
||||
return substr r$ 1 (sl - 1)
|
||||
.
|
||||
|
|
|
|||
40
Task/Rep-string/FutureBasic/rep-string.basic
Normal file
40
Task/Rep-string/FutureBasic/rep-string.basic
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
include "NSLog.incl"
|
||||
|
||||
local fn RepeatingStrings
|
||||
NSUInteger i
|
||||
CFArrayRef testCases = @[@"1001110011", @"1110111011", @"0010010010", @"1010101010",
|
||||
@"1111111111", @"0100101101", @"0100100", @"101", @"11", @"00", @"1"]
|
||||
|
||||
for CFStringRef string in testCases
|
||||
NSUInteger length = len(string)
|
||||
CFMutableArrayRef repeats = fn MutableArrayNew
|
||||
|
||||
for NSUInteger prefixLen = 1 to length / 2
|
||||
BOOL repeatsPrefix = YES
|
||||
|
||||
for i = prefixLen to length - 1
|
||||
if ( fn StringCharacterAtIndex( string, i ) != fn StringCharacterAtIndex( string, (i % prefixLen) ) )
|
||||
repeatsPrefix = NO
|
||||
break
|
||||
end if
|
||||
next
|
||||
|
||||
if ( repeatsPrefix )
|
||||
MutableArrayAddObject( repeats, fn StringSubstringToIndex( string, prefixLen ) )
|
||||
end if
|
||||
next
|
||||
|
||||
CFStringRef outputStr
|
||||
if ( fn ArrayCount(repeats) > 0 )
|
||||
outputStr = fn ArrayComponentsJoinedByString( repeats, @", " )
|
||||
outputStr = fn StringByTrimmingCharactersInSet( outputStr, fn CharacterSetWhitespaceSet )
|
||||
else
|
||||
outputStr = @"(no repeat)"
|
||||
end if
|
||||
NSLog( @"%10s : %@", fn StringUTF8String(string), outputStr )
|
||||
next
|
||||
end fn
|
||||
|
||||
fn RepeatingStrings
|
||||
|
||||
HandleEvents
|
||||
|
|
@ -1,12 +1,7 @@
|
|||
function repstring(r::AbstractString)
|
||||
function repstring(str::AbstractString)
|
||||
r = collect(str)
|
||||
n = length(r)
|
||||
replst = String[]
|
||||
for m in 1:n÷2
|
||||
s = r[1:chr2ind(r, m)]
|
||||
if (s ^ cld(n, m))[1:chr2ind(r, n)] != r continue end
|
||||
push!(replst, s)
|
||||
end
|
||||
return replst
|
||||
return [String(r[1:m]) for m in 1:n÷2 if collect(String(r[1:m]) ^ cld(n, m))[1:n] == r]
|
||||
end
|
||||
|
||||
tests = ["1001110011", "1110111011", "0010010010", "1010101010", "1111111111",
|
||||
|
|
|
|||
28
Task/Rep-string/R/rep-string.r
Normal file
28
Task/Rep-string/R/rep-string.r
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
is_repeated <- function(s) {
|
||||
for (i in 1+(nchar(s) %/% 2):0) {
|
||||
if (startsWith(s, substring(s, i))) {
|
||||
return(i-1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test_strings <- c("1001110011",
|
||||
"1110111011",
|
||||
"0010010010",
|
||||
"1010101010",
|
||||
"1111111111",
|
||||
"0100101101",
|
||||
"0100100",
|
||||
"101",
|
||||
"11",
|
||||
"00",
|
||||
"1")
|
||||
|
||||
result <- sapply(test_strings, is_repeated)
|
||||
repeaters <- substring(test_strings, 1, result)
|
||||
repeaters <- ifelse(repeaters != "", repeaters, "[none]")
|
||||
writeLines(paste(test_strings,
|
||||
"has a repetition length of",
|
||||
result,
|
||||
"with repeating unit",
|
||||
repeaters))
|
||||
37
Task/Rep-string/VBScript/rep-string.vbs
Normal file
37
Task/Rep-string/VBScript/rep-string.vbs
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