Re: Re: Need a nice way to do this
- To: mathgroup at smc.vnet.net
 - Subject: [mg40323] Re: [mg40313] Re: Need a nice way to do this
 - From: Dr Bob <majort at cox-internet.com>
 - Date: Tue, 1 Apr 2003 04:51:53 -0500 (EST)
 - References: <b63r1a$3oc$1@smc.vnet.net> <200303310901.EAA21711@smc.vnet.net>
 - Reply-to: majort at cox-internet.com
 - Sender: owner-wri-mathgroup at wolfram.com
 
Here are timings for that, with a slight modification:
kuska2[lst_] := Module[{l, i, symbs = Union@lst}, Map[(i = 0;
          l[#1] = Map[Function[{x}, If[x =!= #1, i++, i]], lst]) &, symbs];
    MapIndexed[l[#][[First[#2]]] &, lst]]
n = 10000;
test = Array[Random[Integer] &, n];
Timing[drbob[test];]
Timing[drbob2[test];]
Timing[drbob3[test];]
Timing[drbob4[test];]
Timing[andrzej2[test];]
Timing[kuska2[test];]
{0.078 Second,Null}
{0.141 Second,Null}
{0.141 Second,Null}
{0.078 Second,Null}
{0.047 Second,Null}
{0.141 Second,Null}
n = 10000;
test = Array[Round[20Random[]] &, n];
Timing[drbob[test];]
Timing[drbob2[test];]
Timing[drbob3[test];]
Timing[drbob4[test];]
Timing[kuska2[test];]
{0.063 Second,Null}
{0.156 Second,Null}
{0.141 Second,Null}
{0.062 Second,Null}
{1.219 Second,Null}
n = 10000;
test = Array[Round[99Random[]] &, n];
Timing[fisher[test];]
Timing[selwyn2[test];]
Timing[drbob[test];]
Timing[drbob2[test];]
Timing[drbob3[test];]
Timing[drbob4[test];]
Timing[kuska2[test];]
{2.188 Second,Null}
{0.703 Second,Null}
{0.109 Second,Null}
{0.157 Second,Null}
{0.156 Second,Null}
{0.094 Second,Null}
{5.64 Second,Null}
Bobby
On Mon, 31 Mar 2003 04:01:23 -0500 (EST), Jens-Peer Kuska 
<kuska at informatik.uni-leipzig.de> wrote:
> Hi,
>
> UnequalLeft[lst_, symbs_] := Module[{l, i},
> Map[
> (i = 0; l[#1] = Map[Function[{x}, If[x =!= #1, i++, i]] , lst]) &, 
> symbs];
> MapIndexed[l[#][[First[#2]]] &, lst]
> ]
>
> and call it with
>
> UnequalLeft[s, {a, b}]
>
> Regards
> Jens
>
> Steve Gray wrote:
>>
>> Given a list consisting of only two distinct values, such as
>> s={a,b,b,a,a,a,b,a,b,a,a}, I want to derive a list of equal length
>> g={0,1,1,2,2,2,4,3,5,4,4}. The rule is: for each position
>> 1<=p<=Length[s], look at list s and set g[[p]] to the number of
>> elements in s to the left of p which are not equal to s[[p]].
>> In a more general version, which I do  not need now, s would
>> not be restricted to only two distinct values.
>>
>> Thank you for any ideas, including other applications where
>> this particular calculation is used. The current application is an
>> unusual conjecture in geometry.
>
>
-- 
majort at cox-internet.com
Bobby R. Treat