Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,25 @@
|
|||
ClearAll[RosettaShortestCommonSuperSequence]
|
||||
RosettaShortestCommonSuperSequence[aa_String, bb_String] :=
|
||||
Module[{lcs, scs, a = aa, b = bb},
|
||||
lcs = LongestCommonSubsequence[aa, bb];
|
||||
scs = "";
|
||||
While[StringLength[lcs] > 0,
|
||||
If[StringTake[a, 1] == StringTake[lcs, 1] \[And] StringTake[b, 1] == StringTake[lcs, 1],
|
||||
scs = StringJoin[scs, StringTake[lcs, 1]];
|
||||
lcs = StringDrop[lcs, 1];
|
||||
a = StringDrop[a, 1];
|
||||
b = StringDrop[b, 1];
|
||||
,
|
||||
If[StringTake[a, 1] == StringTake[lcs, 1],
|
||||
scs = StringJoin[scs, StringTake[b, 1]];
|
||||
b = StringDrop[b, 1];
|
||||
,
|
||||
scs = StringJoin[scs, StringTake[a, 1]];
|
||||
a = StringDrop[a, 1];
|
||||
]
|
||||
]
|
||||
];
|
||||
StringJoin[scs, a, b]
|
||||
]
|
||||
RosettaShortestCommonSuperSequence["abcbdab", "bdcaba"]
|
||||
RosettaShortestCommonSuperSequence["WEASELS", "WARDANCE"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue