26 Jul
2006
26 Jul
'06
8:53 a.m.
Sukit Tretriluxana wrote:
Dear expert Haskellers,
I am a newbie to Haskell and try to write several algorithms with it. One of them is the string permutation which generates all possible permutations using the characters in the string.
While I could hardly be called an expert haskeller, here's my version: permute :: [a] -> [[a]] permute [] = [[]] permute list = concat $ map (\(x:xs) -> map (x:) (permute xs)) (take (length list) (unfoldr (\x -> Just (x, tail x ++ [head x])) list)) HTH Martin