Haskell's two suggestions:
There may be some examples for this ... just for fun ... Sorting L by individual look:
import Data.List (sortBy,isInfixOf) hsl = (concat . sortBy wierd $ l) == s where wierd ab | isInfixOf (a ++ b) s = LT | isInfixOf (b ++ a) s = GT | otherwise = EQ
More boring ... trying to build S from L:
import Data.List (delete,isPrefixOf) fsl = gsl [] where g str subs result | concat result == s = [result] | otherwise = if null str || null subs' then [] else do sub <- subs' g (drop (length sub) str) (delete sub subs) (result ++ [sub]) where subs' = filter (flip isPrefixOf str) subs
Output:
*Main> f "abcdabce" ["abcd", "a", "bc", "e", "abc"] [["abcd","a","bc","e"],["abcd","abc","e"]] *Main> h "abcdabce" ["abcd", "a", "bc", "e", "abc"] False *Main> h "abcdabce" ["abcd", "a", "bc", "e"] True
source share