MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: easiest way to sort a list?


Both methods suggested by ARNOLDK [arnoldk at gauss.cam.wits.ac.za]work fine.
However, the use of ReplaceRepeated takes an inordinate amount of time. Any
idea why?

In[1]:=
myNumbers = Table[Random[Integer, {1, 99}], {500}];

myNumbers //. {a___, b_, c___, b_, d___} -> {a, b, c, d}; // Timing

Out[2]=
{46.52 Second, Null}

In[3]:=
union2[l_] :=
  Fold[Flatten[If[! MemberQ[#1, #2], Append[#1, #2], #1]] &, {}, l]


In[4]:=
union2[myNumbers]; // Timing

Out[4]=
{0.06 Second, Null}

Tomas Garza
Mexico City



  • Prev by Date: Need just enough underbars
  • Next by Date: Re: Mathematica 2.2 on iMac?
  • Previous by thread: Re: RE: easiest way to sort a list?
  • Next by thread: Re: easiest way to sort a list?