Shortest common supersequence: Difference between revisions

Content added Content deleted
(Haskell added)
Line 258: Line 258:
abdcabdab
abdcabdab
</pre>
</pre>
=={{header|Haskell}}==
{{trans|C++}}
<lang Haskell>scs :: Eq a => [a] -> [a] -> [a]
scs [] ys = ys
scs xs [] = xs
scs xss@(x:xs) yss@(y:ys)
| x == y = x : scs xs ys
| otherwise = ws
where
us = scs xs yss
vs = scs xss ys
ws | length us < length vs = x : us
| otherwise = y : vs


main = putStrLn $ scs "abcbdab" "bdcaba"</lang>
{{out}}
<pre>abdcabdab</pre>
=={{header|Java}}==
=={{header|Java}}==
{{trans|D}}
{{trans|D}}