Re: programming problem about elements taken
- To: mathgroup at smc.vnet.net
- Subject: [mg72484] Re: programming problem about elements taken
- From: Peter Pein <petsie at dordos.net>
- Date: Mon, 1 Jan 2007 03:51:01 -0500 (EST)
- References: <en5evt$l12$1@smc.vnet.net> <en82bm$6nb$1@smc.vnet.net>
Dear group,
please ignore this nonsense.
Thank you.
Peter Pein schrieb:
> Hi Barrow,
>
> the first method coming to my mind has been the use of ReplaceRepeated, but
> for long lists this lasts far too long:
>
>
> A=Table[Random[],{2000}];
> epsilon=1.*^-4;
>
> Timing[Length[
> r1=A//.{x___,c_,y___}/;Min[Abs[c-{x,y}]]<epsilon:>{x,y}
> ]]
>
> --> {22.125 Second,1650}
>
> It is sufficient to compare element k with elements k+1,...,n:
>
> selectDistinguishable[a_List,eps_]:=
> Pick[a,Min[Abs[a[[#]]-Drop[a,#]]]>eps&/@Range[Length[a]]]
>
> Timing[Length[
> r2=selectDistinguishable[A,epsilon]
> ]]
>
> --> {0.11 Second,1650}
>
> _Much_ better :-)
>
> r1===r2
> --> True
>
> hth,
> Peter
>