Skip to content

Instantly share code, notes, and snippets.

@gclaramunt
Created May 22, 2011 04:01
Show Gist options
  • Save gclaramunt/985172 to your computer and use it in GitHub Desktop.
Save gclaramunt/985172 to your computer and use it in GitHub Desktop.
subsequences
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