Permutations by swapping: Difference between revisions
Content added Content deleted
Line 473:
=={{header|Haskell}}==
<lang haskell>
insertEverywhere x [] = [[x]]▼
insertEverywhere x l@(y:ys) = (x:l) : map (y:) (insertEverywhere x ys)▼
where aux items x = do (f, item) <- zip (cycle [reverse, id]) items▼
f (insertEverywhere x item)▼
s_permutations :: [a] -> [([a], Int)]
s_permutations = flip zip (cycle [1, -1]) .
where aux items x = do
main :: IO ()
|