Data update

This commit is contained in:
Ingy döt Net 2026-02-01 16:33:20 -08:00
parent 5150844a7d
commit 4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions

View file

@ -1,30 +0,0 @@
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

@ -5,10 +5,9 @@ lcs: function [a,b][
loop.with:'i a 'x [
loop.with:'j b 'y [
if x=y [
if? or? i=0 j=0 ->
lengths\[i]\[j]: 0
else ->
lengths\[i]\[j]: 1 + lengths\[i-1]\[j-1]
switch or? i=0 j=0
-> lengths\[i]\[j]: 0
-> lengths\[i]\[j]: 1 + lengths\[i-1]\[j-1]
if greatestLength < lengths\[i]\[j] [
greatestLength: lengths\[i]\[j]

View file

@ -1,26 +1,25 @@
(phixonline)-->
<span style="color: #008080;">function</span> <span style="color: #000000;">lcs</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">longest</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">best</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">""</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">ch</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">b</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">ch</span><span style="color: #0000FF;">=</span><span style="color: #000000;">b</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">then</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">n</span><span style="color: #0000FF;"><=</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">a</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">+</span><span style="color: #000000;">n</span><span style="color: #0000FF;"><=</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">b</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">and</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]=</span><span style="color: #000000;">b</span><span style="color: #0000FF;">[</span><span style="color: #000000;">j</span><span style="color: #0000FF;">+</span><span style="color: #000000;">n</span><span style="color: #0000FF;">]</span> <span style="color: #008080;">do</span>
<span style="color: #000000;">n</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">></span><span style="color: #000000;">longest</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">longest</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">n</span>
<span style="color: #000000;">best</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">..</span><span style="color: #000000;">i</span><span style="color: #0000FF;">+</span><span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">]</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">return</span> <span style="color: #000000;">best</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">lcs</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"thisisatest"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"testing123testing"</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">lcs</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"testing123testing"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"thisisatest"</span><span style="color: #0000FF;">)</span>
<!--
function lcs(string a, b)
integer la = length(a),
lb = length(b),
longest = 0
string best = ""
for i,ch in a do
for j=1 to lb do
if ch=b[j] then
integer l=1
while i+l<=la
and j+l<=lb
and a[i+l]=b[j+l] do
l += 1
end while
if l>longest then
longest = l
best = a[i..i+l-1]
end if
end if
end for
end for
return best
end function
?lcs("thisisatest","testing123testing")
?lcs("testing123testing","thisisatest")

View file

@ -1,62 +0,0 @@
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

@ -1,20 +1,53 @@
/*REXX program determines the LCSUBSTR (Longest Common Substring) via a function. */
parse arg a b . /*obtain optional arguments from the CL*/
if a=='' then a= "thisisatest" /*Not specified? Then use the default.*/
if b=='' then b= "testing123testing" /* " " " " " " */
say ' string A =' a /*echo string A to the terminal screen.*/
say ' string B =' b /* " " B " " " " */
say ' LCsubstr =' LCsubstr(a, b) /*display the Longest Common Substring.*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
LCsubstr: procedure; parse arg x,y,,$; #= 0 /*LCsubstr: Longest Common Substring. */
L= length(x); w= length(y) /*placeholders for string length of X,Y*/
if w<L then do; parse arg y,x; L= w /*switch X & Y if Y is shorter than X*/
end
do j=1 for L while j<=L-# /*step through start points in string X*/
do k=L-j+1 to # by -1 /*step through string lengths. */
_= substr(x, j, k) /*extract a possible common substring. */
if pos(_, y)\==0 then if k># then do; $= _; #= k; end
end /*k*/ /* [↑] determine if string _ is longer*/
end /*j*/ /*#: the current length of $ string.*/
return $ /*$: (null if there isn't common str.)*/
/*REXX program determines the longest Common Substring via a function.*/
Parse Arg a b . /* obtain arguments from command line */
Select
When a='?'Then Do /*Not specified? prompt for strings */
Say 'Enter two strings'
Parse Pull a
Parse Pull b
End
When a='' Then Do /* else use defaults */
a='thisisatest'
b='testing123testing'
End
Otherwise
Nop
End
cs=LCsubstr(a,b)
Say ' st A ='||a pax /*show string A and start position */
Say ' st B ='||b pbx /* " " B " " " " */
Say ' LCtr ='||cs /*show the Longest Common Substring */
Exit
/*---------------------------------------------------------------------*/
LCsubstr: Procedure Expose pax pbx /*LCsubstr: Longest Common Substring*/
Parse Arg stra,strb,,d /* get two strings and set d='' */
ll=0 /* length of common substring so far */
la=length(stra) /* length of the two strings */
lb=length(strb)
switch=0
If lb<la Then Do /* make the shorter string stra */
Parse Arg strb,stra
switch=1
la=lb
End
Do pa=1 for la while pa<=la-ll
Do k=la-pa+1 to ll By -1
ss=substr(stra,pa,k) /* a substring */
pb=pos(ss,strb)
If pb\==0 Then Do /* also found in strb */
If k>ll Then Do /* longer than one found before */
d=ss /* remember the string */
ll=k /* and its length */
If switch Then /* note the start positions */
Parse Value pb pa With pax pbx
Else
Parse Value pa pb With pax pbx
End
End
End
End
If d='' Then Do
d='no common substring found'
Parse Value '' With pax pbx
End
return d

View file

@ -1,14 +0,0 @@
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))