Sorting algorithms/Permutation sort: Difference between revisions
Content added Content deleted
ReeceGoding (talk | contribs) (→RcppAlgos: Commented on an alternative loop.) |
|||
Line 1,518: | Line 1,518: | ||
<pre>[-1,0,0,17,72]</pre> |
<pre>[-1,0,0,17,72]</pre> |
||
=={{header|Mathematica}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
Here is a one-line solution. |
Here is a one-line solution. |
||
A custom order relation can be defined for the OrderedQ[] function. |
A custom order relation can be defined for the OrderedQ[] function. |
||
<lang Mathematica>PermutationSort[x_List] := NestWhile[RandomSample, x, Not[OrderedQ[#]] &]</lang> |
<lang Mathematica>PermutationSort[x_List] := NestWhile[RandomSample, x, Not[OrderedQ[#]] &]</lang> |
||