Shortest common supersequence: Difference between revisions
Add Factor
(Add Factor) |
|||
Line 185:
<pre>
SCS(abcbdab, bdcaba) = abdcabdab
</pre>
=={{header|Factor}}==
{{trans|Julia}}
<lang factor>USING: combinators io kernel locals math memoize sequences ;
MEMO:: scs ( x y -- seq )
{
{ [ x empty? ] [ y ] }
{ [ y empty? ] [ x ] }
{ [ x first y first = ]
[ x rest y rest scs x first prefix ] }
{ [ x y rest scs length x rest y scs length <= ]
[ x y rest scs y first prefix ] }
[ x rest y scs x first prefix ]
} cond ;
"abcbdab" "bdcaba" scs print</lang>
{{out}}
<pre>
abdcabdab
</pre>
|