Function Repository Resource:

StupidSort

Source Notebook

Just like Sort, but works much more stupidly

Contributed by: Tang Anke

ResourceFunction["StupidSort"][list]

inefficiently sorts the elements of list into canonical order.

Details and Options

The time complexity is about O(n3logn).
ResourceFunction["StupidSort"] algorithmically replaces list with the rule {x___,a_,b_,y___}/;a>b{x,b,a,y} until no match can be found.

Examples

Basic Examples (2) 

Create an array of 10 random values:

In[1]:=
data = RandomReal[{-10, 10}, 10]
Out[1]=

Stupidly sort the random array:

In[2]:=
ResourceFunction["StupidSort"][data]
Out[2]=

Properties and Relations (5) 

Create an array:

In[3]:=
data = RandomReal[{-10, 10}, 300];

StupidSort takes several seconds to sort the data:

In[4]:=
First@AbsoluteTiming@(stupidresult = ResourceFunction["StupidSort"][data])
Out[4]=

Use Sort instead:

In[5]:=
First@AbsoluteTiming@(smartresult = Sort[data])
Out[5]=

Sort is much less stupid:

In[6]:=
%/%%
Out[6]=

Even so, both methods give the same result:

In[7]:=
stupidresult === smartresult
Out[7]=

Publisher

Tang anke

Version History

  • 1.0.0 – 26 March 2020

Related Resources

License Information