Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,30 @@
with Ada.Text_Io;
procedure Longest_Common_Substring is
function Common (Left, Right: String) return String is
Com : array (Left'Range, Right'Range) of Natural := (others => (others => 0));
Longest : Natural := 0;
Last : Natural := 0;
begin
for L in Left'Range loop
for R in Right'Range loop
if Left (L) = Right (R) then
if L > Left'First and R > Right'First then
Com (L, R) := Com (L - 1, R - 1) + 1;
else
Com (L, R) := 1;
end if;
if Com (L, R) > Longest then
Longest := Com (L, R);
Last := L;
end if;
end if;
end loop;
end loop;
return Left (Last - Longest + 1 .. Last);
end Common;
begin
Ada.Text_Io.Put_Line (Common ("thisisatest", "testing123testing"));
end Longest_Common_Substring;

View file

@ -0,0 +1,21 @@
procedure lcs(s1,s2) # return longest common substring of s1 and s2
if *s1 > *s2 then s1 :=: s2 # s1 is the shorter string
return s1 ? if j := *s1 to 1 by -1 & # Return substring, s, of s1 that is
tab(1 to *s1) & # also a substring of s2. Evaluate s from
find(s := move(j),s2) then s else "" # longest to shortest.
end
procedure main(A)
lcstest("thisisatest","testing123testing")
lcstest("abracadabra","arabracae")
lcstest("abc","123")
lcstest("testing","sting")
lcstest("thisisatest_stinger","testing123testingthing")
lcstest("thisisatest_stinger","thisis")
lcstest("testing123testingthing","thisis")
lcstest("thisisatest","thisisatest")
end
procedure lcstest(s1,s2)
write("\"",s1,"\" and ","\"",s2,"\" --> \"",lcs(s1,s2),"\"")
end

View file

@ -0,0 +1,19 @@
procedure main(A)
s1 := \A[1] | "thisisatest"
s2 := \A[2] | "testing123testing"
write(s1)
write(s2)
write("---")
write(lcs(s1,s2))
end
procedure lcs(s1,s2)
lc := ""
s1 ? every (tab(upto(s2)), c1 := move(1), cs:="") do {
while p2 := upto(c1, s2) do
while (c1 == s2[p2]) | break break do
(cs ||:= c1, p2 +:= 1, c1 := move(1))
if *cs > *lc then lc := cs
}
return lc
end

View file

@ -0,0 +1,62 @@
function lcs([String]$a, [String]$b)
{
if ([String]::IsNullOrEmpty($a) -or [String]::IsNullOrEmpty($b))
{
return ""
}
$startIndex, $size = -1, -1
for ($k = 0; $k -lt $a.Length; ++$k)
{
for ($i, $j, $d = $k, 0, 0; ($i -lt $a.Length) -and ($j -lt $b.Length); ++$i, ++$j)
{
if ($a.Chars($i) -eq $b.Chars($j))
{
$d += 1
if ($size -lt $d)
{
$startIndex = $i - $d + 1
$size = $d
}
}
else
{
$d = 0
}
}
}
for ($k = 1; $k -lt $b.Length; ++$k)
{
for ($i, $j, $d = 0, $k, 0; ($i -lt $a.Length) -and ($j -lt $b.Length); ++$i, ++$j)
{
if ($a.Chars($i) -eq $b.Chars($j))
{
$d += 1
if ($size -lt $d)
{
$startIndex = $i - $d + 1
$size = $d
}
}
else
{
$d = 0
}
}
}
if ($size -lt 0)
{
return ""
}
return $a.Substring($startIndex, $size)
}
function Print-Lcs([String]$a, [String]$b)
{
return "lcs $a $b = $(lcs $a $b)"
}
Print-Lcs 'thisisatest' 'testing123testing'
Print-Lcs 'testing' 'sting'
Print-Lcs 'thisisatest_stinger' 'testing123testingthing'
Print-Lcs 'thisisatest_stinger' 'thisis'
Print-Lcs 'testing123testingthing' 'thisis'
Print-Lcs 'thisisatest' 'thisisatest'

View file

@ -0,0 +1,14 @@
Function lcs(string1,string2)
For i = 1 To Len(string1)
tlcs = tlcs & Mid(string1,i,1)
If InStr(string2,tlcs) Then
If Len(tlcs) > Len(lcs) Then
lcs = tlcs
End If
Else
tlcs = ""
End If
Next
End Function
WScript.Echo lcs(WScript.Arguments(0),WScript.Arguments(1))