Permutations: Difference between revisions
Content deleted Content added
→{{header|Mathematica}}: Added output |
→{{header|Haskell}}: A serialized version |
||
Line 2,938: | Line 2,938: | ||
insertEverywhere x [] = [[x]] |
insertEverywhere x [] = [[x]] |
||
insertEverywhere x l@(y:ys) = (x:l) : map (y:) (insertEverywhere x ys)</lang> |
insertEverywhere x l@(y:ys) = (x:l) : map (y:) (insertEverywhere x ys)</lang> |
||
A serialized version (based on [[#Mathematica|the Mathematica version]]): |
|||
<lang haskell> |
|||
import qualified Data.List as L |
|||
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) (length l))) |
|||
[[]] s |
|||
</lang> |
|||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |