Permutations: Difference between revisions

f# second version - based on Haskell insertion-based approach
(→‎{{header|Ruby}}: Removed 1.8.7 version info; task specifies different objects -removed code handling duplicates)
(f# second version - based on Haskell insertion-based approach)
Line 2,031:
0
</lang>
 
<pre>
&gt;RosettaPermutations 1 2 3
Line 2,040 ⟶ 2,041:
["3"; "2"; "1"]
</pre>
 
Translation of Haskell "insertion-based approach" (last version)
<lang fsharp>
let permutations xs =
let rec insert x = function
| [] -> [[x]]
| head :: tail -> (x :: (head :: tail)) :: (List.map (fun l -> head :: l) (insert x tail))
List.fold (fun s e -> List.collect (insert e) s) [[]] xs
</lang>
 
=={{header|Factor}}==