MathGroup Archive 2003

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

Search the Archive

Re: Re: Need a nice way to do this

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40520] Re: Re: Need a nice way to do this
  • From: "Carl K. Woll" <carlw at u.washington.edu>
  • Date: Wed, 9 Apr 2003 01:32:16 -0400 (EDT)
  • Organization: University of Washington
  • References: <200304070853.EAA07971@smc.vnet.net> <b6tsjh$n0r$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Bobby,

You didn't mention Hartmut Wolf's solution, but then his function wouldn't
work on your test data. However, his basic idea demonstrates a useful
technique, since he increments a symbol, and not a function of a symbol as
most of the other solutions do. We can incorporate this concept and arrive
at the following function:

carl[s_] := Block[{f},
    f[i_] := With[{j = Unique[]}, f[i] := ++j; j = 1];
    Range[Length[s]] - f /@ s]

In my timing tests, this function is faster than all of the others that have
been posted.

Carl Woll
Physics Dept
U of Washington

"Dr Bob" <majort at cox-internet.com> wrote in message
news:b6tsjh$n0r$1 at smc.vnet.net...
> We have a new winner! (For two-value lists.)
>
> n = 100000;
> test = Array[Random[Integer] &, n];
> Timing[drbob[test];]
> Timing[drbob2[test];]
> Timing[drbob3[test];]
> Timing[drbob4[test];]
> Timing[andrzej2[test];]
> Timing[kuska2[test];]
> Timing[deLouis2[test];]
>
> {0.781 Second,Null}
> {1.328 Second,Null}
> {1.328 Second,Null}
> {0.735 Second,Null}
> {0.5 Second,Null}
> {1.344 Second,Null}
> {0.328 Second,Null}
>
> Bobby
>
> On Mon, 7 Apr 2003 04:53:53 -0400 (EDT), Dana DeLouis
> <delouis at bellsouth.net> wrote:
>
> > Hello.  I'm too new at this to contribute much.
> > I modified Andrzej's second code slightly for two variables.  I seem to
> > get
> > a 30% speed increase with the following idea.
> > f3[s_List] := Module[
> > {v, t}, v = Length /@ Split[s]; t = Transpose[Partition[v, 2, 2, {1, 1},
> > 0]]; t = (FoldList[Plus, 0, #1] & ) /@ t; t =
> > Take[Rest[Flatten[Transpose[t]]], Length[v]];
Flatten[MapThread[Table[#1,
> > {#2}] & , {t, v}]]
> > ]
> >
>
>
>
> --
> majort at cox-internet.com
> Bobby R. Treat
>
>




  • Prev by Date: Re: Adobe Illustrator exporting
  • Next by Date: Re: Re: Need a nice way to do this
  • Previous by thread: Re: Re: Need a nice way to do this
  • Next by thread: Re: Re: Need a nice way to do this