RosettaCodeData/Task/Longest-common-subsequence/Haskell/longest-common-subsequence-5.hs
Ingy döt Net 776bba907c Sync
2013-10-27 22:24:23 +00:00

10 lines
346 B
Haskell

import Data.List
longest xs ys = if length xs > length ys then xs else ys
lcs xs ys = head $ foldr(\xs -> map head. scanr1 f. zipWith (\x y -> [x,y]) xs) e m where
m = map (\x -> flip (++) [[]] $ map (\y -> [x | x==y]) ys) xs
e = replicate (length ys) []
f [a,b] [c,d]
| null a = longest b c: [b]
| otherwise = (a++d):[b]