Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,7 @@
|
|||
longest xs ys = if length xs > length ys then xs else ys
|
||||
|
||||
lcs [] _ = []
|
||||
lcs _ [] = []
|
||||
lcs (x:xs) (y:ys)
|
||||
| x == y = x : lcs xs ys
|
||||
| otherwise = longest (lcs (x:xs) ys) (lcs xs (y:ys))
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import qualified Data.MemoCombinators as M
|
||||
|
||||
lcs = memoize lcsm
|
||||
where
|
||||
lcsm [] _ = []
|
||||
lcsm _ [] = []
|
||||
lcsm (x:xs) (y:ys)
|
||||
| x == y = x : lcs xs ys
|
||||
| otherwise = maxl (lcs (x:xs) ys) (lcs xs (y:ys))
|
||||
|
||||
maxl x y = if length x > length y then x else y
|
||||
memoize = M.memo2 mString mString
|
||||
mString = M.list M.char -- Chars, but you can specify any type you need for the memo
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import Data.Array
|
||||
|
||||
lcs xs ys = a!(0,0) where
|
||||
n = length xs
|
||||
m = length ys
|
||||
a = array ((0,0),(n,m)) $ l1 ++ l2 ++ l3
|
||||
l1 = [((i,m),[]) | i <- [0..n]]
|
||||
l2 = [((n,j),[]) | j <- [0..m]]
|
||||
l3 = [((i,j), f x y i j) | (x,i) <- zip xs [0..], (y,j) <- zip ys [0..]]
|
||||
f x y i j
|
||||
| x == y = x : a!(i+1,j+1)
|
||||
| otherwise = longest (a!(i,j+1)) (a!(i+1,j))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
*Main> lcs "thisisatest" "testing123testing"
|
||||
"tsitest"
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
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]
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import Data.Ord
|
||||
import Data.List
|
||||
|
||||
-- longest common
|
||||
lcs xs ys = maximumBy (comparing length) $ intersect (subsequences xs) (subsequences ys)
|
||||
|
||||
main = print $ lcs "thisisatest" "testing123testing"
|
||||
Loading…
Add table
Add a link
Reference in a new issue