MathGroup Archive 1999

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

Search the Archive

Re: Re: easiest way to sort a list?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18338] Re: [mg18320] Re: [mg18308] easiest way to sort a list?
  • From: "Tomas Garza" <tgarza at mail.internet.com.mx>
  • Date: Sun, 27 Jun 1999 15:11:24 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

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?