Sorting algorithms/Permutation sort: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 115:
| h :: t as l -> (e :: l) :: List.map (fun t' -> h :: t') (insert e t)
 
let permute xs = List.fold_right (fun h z -> List.concat (List.map (insert h) z))
let rec permute = function
| [] -> xs [[]]
| h :: t -> List.concat (List.map (fun t' -> insert h t') (permute t))
 
let permutation_sort l = List.find sorted (permute l)</lang>
Line 133 ⟶ 132:
=={{header|Python}}==
{{works with|Python|2.6}}
<lang python>from itertools import permutations, ifilter
 
in_order = lambda s: all(x <= s[i+1] for i,x in enumerate(s[:-1]))
Anonymous user