Data update

This commit is contained in:
Ingy döt Net 2023-12-16 21:33:55 -08:00
parent 35bcdeebf8
commit 74c69a0df6
2427 changed files with 31826 additions and 3468 deletions

View file

@ -0,0 +1,5 @@
lcs{
sb,/{¨,\}¨,\
match(sb(/)¨)/sb
((/=)¨match)/match
}

View file

@ -0,0 +1,2 @@
'testing123testing' lcs 'thisisatest'
test

View file

@ -0,0 +1,48 @@
include "cowgol.coh";
include "strings.coh";
sub Contains(s1: [uint8], s2: [uint8]): (r: uint8) is
r := 0;
while [s1] != 0 loop
var a := s1;
var b := s2;
while [b] != 0 and [a] == [b] loop
a := @next a;
b := @next b;
end loop;
if [b] == 0 then
r := 1;
return;
end if;
s1 := @next s1;
end loop;
end sub;
sub LCS(s1: [uint8], s2: [uint8], outbuf: [uint8]) is
if StrLen(s1) < StrLen(s2) then
var temp := s1;
s1 := s2;
s2 := temp;
end if;
var maxlen := StrLen(s2);
var length := maxlen;
while length > 0 loop
var start: intptr := 0;
while start + length <= maxlen loop
MemCopy(s2 + start, length, outbuf);
[outbuf + length + 1] := 0;
if Contains(s1, outbuf) != 0 then
return;
end if;
start := start + 1;
end loop;
length := length - 1;
end loop;
[outbuf] := 0;
end sub;
var lcs: uint8[64];
LCS("thisisatest", "testing123testing", &lcs[0]);
print(&lcs[0]);
print_nl();

View file

@ -0,0 +1,31 @@
[ 0 temp put
0 temp put
tuck dup size times
[ 2dup swap
0 temp put
0 swap witheach
[ unrot
over size
over = iff
[ drop
conclude ]
done
rot dip
[ 2dup peek ]
= tuck * +
dup temp take
max temp put ]
2drop
temp take
dup temp share > iff
[ temp release
i^ temp replace
temp put ]
else drop
behead drop ]
2drop
temp take dip
[ temp take split nip ]
split drop ] is lcs ( $ $ --> $ )
$ "thisisatest" $ "testing123testing" lcs echo$ cr

View file

@ -0,0 +1,17 @@
program longest_common_substring;
print(lcs("thisisatest", "testing123testing"));
proc lcs(s1, s2);
if #s1 < #s2 then [s1, s2] := [s2, s1]; end if;
loop for l in [#s2, #s2-1..1] do
loop for s in [1..#s2-l+1] do
if (substr := s2(s..s+l)) in s1 then
return substr;
end if;
end loop;
end loop;
return "";
end proc;
end program;