Created
May 22, 2011 04:01
-
-
Save gclaramunt/985172 to your computer and use it in GitHub Desktop.
subsequences
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
subseq :: Int ->[a]->[[a]] | |
subseq _ [] = [] | |
subseq n xs | len_xs<n = [] | |
| len_xs==n = [xs] | |
| otherwise = take n xs : subseq n (tail xs) | |
where len_xs = length xs | |
subseq' :: Int ->[a]->[[a]] | |
subseq' n xs = filter (flip isInfixOf xs) (filter ( eq_len ) (subsequences xs) ) where eq_len ys = length ys == n | |
continuousSubSeqs = filter (not . null) . concatMap inits . tails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment