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,37 @@
with Ada.Text_IO;
procedure Shortest is
function Scs (Left, Right : in String) return String is
Left_Tail : String renames Left (Left'First + 1 .. Left'Last);
Right_Tail : String renames Right (Right'First + 1 .. Right'Last);
begin
if Left = "" then return Right; end if;
if Right = "" then return Left; end if;
if Left (Left'First) = Right (Right'First) then
return Left (Left'First) & Scs (Left_Tail, Right_Tail);
end if;
declare
S1 : constant String := Scs (Left, Right_Tail);
S2 : constant String := Scs (Left_Tail, Right);
begin
return (if S1'Length <= S2'Length
then Right (Right'First) & S1
else Left (Left'First) & S2);
end;
end Scs;
procedure Exercise (Left, Right : String) is
use Ada.Text_Io;
begin
Put ("scs ( "); Put (Left); Put (" , "); Put (Right); Put ( " ) -> ");
Put (Scs (Left, Right));
New_Line;
end Exercise;
begin
Exercise ("abcbdab", "bdcaba");
Exercise ("WEASELS", "WARDANCE");
end Shortest;

View file

@ -0,0 +1,25 @@
class ShortestCommonSuperSequence {
static isEmpty(s) {
return s == null || s.length === 0;
}
static scs(x, y) {
if (this.isEmpty(x)) {
return y;
}
if (this.isEmpty(y)) {
return x;
}
if (x[0] === y[0]) {
return x[0] + this.scs(x.slice(1), y.slice(1));
}
if (this.scs(x, y.slice(1)).length <= this.scs(x.slice(1), y).length) {
return y[0] + this.scs(x, y.slice(1));
} else {
return x[0] + this.scs(x.slice(1), y);
}
}
static main(args) {
console.log(this.scs("abcbdab", "bdcaba"));
}
}
ShortestCommonSuperSequence.main();