Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -12,5 +12,6 @@ BEGIN PROC lcs = (STRING s, t) STRING:
|
|||
(UPB u > UPB v | u | v)
|
||||
FI;
|
||||
|
||||
print((lcs ("thisisatest", "testing123testing"), new line))
|
||||
print ((lcs ("1234", "1224533324"), new line));
|
||||
print ((lcs ("thisisatest", "testing123testing"), new line))
|
||||
END
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Test_LCS is
|
||||
function LCS (A, B : String) return String is
|
||||
begin
|
||||
if A'Length = 0 or else B'Length = 0 then
|
||||
return "";
|
||||
elsif A (A'Last) = B (B'Last) then
|
||||
return LCS (A (A'First..A'Last - 1), B (B'First..B'Last - 1)) & A (A'Last);
|
||||
else
|
||||
declare
|
||||
X : String renames LCS (A, B (B'First..B'Last - 1));
|
||||
Y : String renames LCS (A (A'First..A'Last - 1), B);
|
||||
begin
|
||||
if X'Length > Y'Length then
|
||||
return X;
|
||||
else
|
||||
return Y;
|
||||
end if;
|
||||
end;
|
||||
end if;
|
||||
end LCS;
|
||||
begin
|
||||
Put_Line (LCS ("thisisatest", "testing123testing"));
|
||||
end Test_LCS;
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Test_LCS is
|
||||
function LCS (A, B : String) return String is
|
||||
L : array (A'First..A'Last + 1, B'First..B'Last + 1) of Natural;
|
||||
begin
|
||||
for I in L'Range (1) loop
|
||||
L (I, B'First) := 0;
|
||||
end loop;
|
||||
for J in L'Range (2) loop
|
||||
L (A'First, J) := 0;
|
||||
end loop;
|
||||
for I in A'Range loop
|
||||
for J in B'Range loop
|
||||
if A (I) = B (J) then
|
||||
L (I + 1, J + 1) := L (I, J) + 1;
|
||||
else
|
||||
L (I + 1, J + 1) := Natural'Max (L (I + 1, J), L (I, J + 1));
|
||||
end if;
|
||||
end loop;
|
||||
end loop;
|
||||
declare
|
||||
I : Integer := L'Last (1);
|
||||
J : Integer := L'Last (2);
|
||||
R : String (1..Integer'Max (A'Length, B'Length));
|
||||
K : Integer := R'Last;
|
||||
begin
|
||||
while I > L'First (1) and then J > L'First (2) loop
|
||||
if L (I, J) = L (I - 1, J) then
|
||||
I := I - 1;
|
||||
elsif L (I, J) = L (I, J - 1) then
|
||||
J := J - 1;
|
||||
else
|
||||
I := I - 1;
|
||||
J := J - 1;
|
||||
R (K) := A (I);
|
||||
K := K - 1;
|
||||
end if;
|
||||
end loop;
|
||||
return R (K + 1..R'Last);
|
||||
end;
|
||||
end LCS;
|
||||
begin
|
||||
Put_Line (LCS ("thisisatest", "testing123testing"));
|
||||
end Test_LCS;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
lcs: function [a,b][
|
||||
ls: new array.of: @[inc size a, inc size b] 0
|
||||
ls: array.of: @[inc size a, inc size b] 0
|
||||
|
||||
loop.with:'i a 'x [
|
||||
loop.with:'j b 'y [
|
||||
|
|
@ -7,13 +7,13 @@ lcs: function [a,b][
|
|||
-> max @[ls\[i+1]\[j], ls\[i]\[j+1]]
|
||||
]
|
||||
]
|
||||
[result, x, y]: @[new "", size a, size b]
|
||||
[result, x, y]: @["", size a, size b]
|
||||
|
||||
while [and? [x > 0][y > 0]][
|
||||
if? ls\[x]\[y] = ls\[x-1]\[y] -> x: x-1
|
||||
else [
|
||||
if? ls\[x]\[y] = ls\[x]\[y-1] -> y: y-1
|
||||
else [
|
||||
switch ls\[x]\[y] = ls\[x-1]\[y] -> x: x-1
|
||||
[
|
||||
switch ls\[x]\[y] = ls\[x]\[y-1] -> y: y-1
|
||||
[
|
||||
result: a\[x-1] ++ result
|
||||
x: x-1
|
||||
y: y-1
|
||||
|
|
|
|||
|
|
@ -2,25 +2,16 @@ func$ right a$ n .
|
|||
return substr a$ (len a$ - n + 1) n
|
||||
.
|
||||
func$ left a$ n .
|
||||
if n < 0
|
||||
n = len a$ + n
|
||||
.
|
||||
if n < 0 : n = len a$ + n
|
||||
return substr a$ 1 n
|
||||
.
|
||||
func$ lcs a$ b$ .
|
||||
if len a$ = 0 or len b$ = 0
|
||||
return ""
|
||||
.
|
||||
if right a$ 1 = right b$ 1
|
||||
return lcs left a$ -1 left b$ -1 & right a$ 1
|
||||
.
|
||||
if len a$ = 0 or len b$ = 0 : return ""
|
||||
if right a$ 1 = right b$ 1 : return lcs left a$ -1 left b$ -1 & right a$ 1
|
||||
x$ = lcs a$ left b$ -1
|
||||
y$ = lcs left a$ -1 b$
|
||||
if len x$ > len y$
|
||||
return x$
|
||||
else
|
||||
return y$
|
||||
.
|
||||
if len x$ > len y$ : return x$
|
||||
return y$
|
||||
.
|
||||
print lcs "1234" "1224533324"
|
||||
print lcs "thisisatest" "testing123testing"
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
function Get-Lcs ($ReferenceObject, $DifferenceObject)
|
||||
{
|
||||
$longestCommonSubsequence = @()
|
||||
$x = $ReferenceObject.Length
|
||||
$y = $DifferenceObject.Length
|
||||
|
||||
$lengths = New-Object -TypeName 'System.Object[,]' -ArgumentList ($x + 1), ($y + 1)
|
||||
|
||||
for($i = 0; $i -lt $x; $i++)
|
||||
{
|
||||
for ($j = 0; $j -lt $y; $j++)
|
||||
{
|
||||
if ($ReferenceObject[$i] -ceq $DifferenceObject[$j])
|
||||
{
|
||||
$lengths[($i+1),($j+1)] = $lengths[$i,$j] + 1
|
||||
}
|
||||
else
|
||||
{
|
||||
$lengths[($i+1),($j+1)] = [Math]::Max(($lengths[($i+1),$j]),($lengths[$i,($j+1)]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (($x -ne 0) -and ($y -ne 0))
|
||||
{
|
||||
if ( $lengths[$x,$y] -eq $lengths[($x-1),$y])
|
||||
{
|
||||
--$x
|
||||
}
|
||||
elseif ($lengths[$x,$y] -eq $lengths[$x,($y-1)])
|
||||
{
|
||||
--$y
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($ReferenceObject[($x-1)] -ceq $DifferenceObject[($y-1)])
|
||||
{
|
||||
$longestCommonSubsequence = ,($ReferenceObject[($x-1)]) + $longestCommonSubsequence
|
||||
}
|
||||
|
||||
--$x
|
||||
--$y
|
||||
}
|
||||
}
|
||||
|
||||
$longestCommonSubsequence
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
(Get-Lcs -ReferenceObject "thisisatest" -DifferenceObject "testing123testing") -join ""
|
||||
|
|
@ -1 +0,0 @@
|
|||
Get-Lcs -ReferenceObject @(1,2,3,4) -DifferenceObject @(1,2,2,4,5,3,3,3,2,4)
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
$list1
|
||||
|
||||
ID X Y
|
||||
-- - -
|
||||
1 101 201
|
||||
2 102 202
|
||||
3 103 203
|
||||
4 104 204
|
||||
5 105 205
|
||||
6 106 206
|
||||
7 107 207
|
||||
8 108 208
|
||||
9 109 209
|
||||
|
||||
$list2
|
||||
|
||||
ID X Y
|
||||
-- - -
|
||||
1 101 201
|
||||
3 103 203
|
||||
5 105 205
|
||||
7 107 207
|
||||
9 109 209
|
||||
|
||||
Get-Lcs -ReferenceObject $list1.ID -DifferenceObject $list2.ID
|
||||
Loading…
Add table
Add a link
Reference in a new issue