Permutations: Difference between revisions

(→‎{{header|Haskell}}: A serialized version)
Line 2,944:
ins :: [a] -> a -> Int -> [a]
ins list x n = listn ++ [x] ++ listn' where (listn,listn')=L.splitAt n list
table f n = [f k | k <- [0..n] ]
permutations :: [a] -> [[a]]
permutations s =
foldl (\ac x->
ac >>= (\l-> table (\k->ins l x k) (<$> [0..length l)]))
[[]] s
</lang>
Anonymous user