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]work fine.
However, the use of ReplaceRepeated takes an inordinate amount of time. Any
idea why?

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

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

{46.52 Second, Null}

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

union2[myNumbers]; // Timing

{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?