Re: Re: Re: position of sequence of
- To: mathgroup at smc.vnet.net
- Subject: [mg107023] Re: [mg107012] Re: [mg106993] Re: [mg106976] position of sequence of
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Mon, 1 Feb 2010 06:09:29 -0500 (EST)
- References: <201001301212.HAA25132@smc.vnet.net>
Hi Patrick,
and therefore, my next guess would have been something like
>
> pos[l_List, what_List] :=
> ReplaceList[
> l, {head___, Sequence @@ what, ___} :> Length[{head}] + 1]
>
>
Well, I wish my next guess would be this. I used this idiom before but it is
not in my active vocabulary, so instead I made a mess with Compile and
wasted lots of time - mine and all those who read my posts.
Regards,
Leonid
>
>
>
> > and therefore, your constructs don't seem to work for me. They seem to
> work
> > only because you provided length - 2 or length- 3 sequences (try length-4
> > and I am getting en error for v7), which Position interprets as 2 or 3
> > additional arguments. Thus,
> >
> > Position[list, Sequence[11, 12, 13]] is equivalent to
> >
> > Position[list, 11,12,13], which means:
> >
> > find position of element <11> in the first 12 levels of expression
> (<list>),
> > stopping with at most 13 results. By accident (or luck), this gives
> correct
> > result on the toy example that you have. The same situation with Bob's
> > example Position[list, Sequence[3, 4]].
> > Or is this an extension of v.7.1, that I am not aware of?
> >
> > Regards,
> > Leonid
> >
> > On Sun, Jan 31, 2010 at 2:55 AM, Patrick Scheibe <
> > pscheibe at trm.uni-leipzig.de> wrote:
> >
> > > Hi,
> > >
> > > I assume the only thing you miss is how to express a "sequence of
> > > numbers"? Just use Sequence[] :-)
> > >
> > > list=Range[20];
> > > Position[list, Sequence[11, 12, 13]]
> > >
> > > Cheers
> > > Patrick
> > >
> > > On Sat, 2010-01-30 at 07:12 -0500, JB wrote:
> > > > Hi,
> > > >
> > > > What is the most efficient way to find the position of the beginning
> > > > of a sequence of numbers from a list?
> > > >
> > > > I found a couple of ways:
> > > >
> > > > find 3,4 in list={1,2,3,4,5};
> > > >
> > > > 1. pos=Intersection[Position[list,3],(Position[list,4])+1]
> > > >
> > > > 2. pos=Position[Partition[list,2,1],{3,4}]
> > > >
> > > > Are there other ways to do this?
> > > > What is the best way when dealing with large lists?
> > > >
> > > > Thanks,
> > > > JB
> > > >
> > >
> > >
> > >
> >
>
>
--002354530710f4c28a047e794078
Content-Type: text/html; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable
X-Sun-Content-Length: 3159
Hi Patrick, <br><br><div class="gmail_quote"><blockquote class="gmail_q=
uote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0=
pt 0.8ex; padding-left: 1ex;">
and therefore, my next guess would have been something like<br>
<br>
pos[l_List, what_List] :=<br>
ReplaceList[<br>
l, {head___, Sequence @@ what, ___} :> Length[{head}] + 1]<br>
<br></blockquote><div><br>Well, I wish my next guess would be this. I used =
this idiom before but it is not in my active vocabulary, so instead I made =
a mess with Compile and wasted lots of time - mine and all those who read m=
y posts.<br>
<br>Regards,<br>Leonid <br><br> </div><blockquote class="gmail_quote" s=
tyle="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8e=
x; padding-left: 1ex;">
<font color="#888888"><br>
</font><div><div class="h5"><br>
<br>
> and therefore, your constructs don't seem to work for me. They see=
m to work<br>
> only because you provided length - 2 or length- 3 sequences (try lengt=
h-4<br>
> and I am getting en error for v7), which Position interprets as 2 or 3=
<br>
> additional arguments. Thus,<br>
><br>
> Position[list, Sequence[11, 12, 13]] is equivalent to<br>
><br>
> Position[list, 11,12,13], which means:<br>
><br>
> find position of element <11> in the first 12 levels of expressi=
on (<list>),<br>
> stopping with at most 13 results. By accident (or luck), this gives co=
rrect<br>
> result on the toy example that you have. The same situation with Bob&#=
39;s<br>
> example Position[list, Sequence[3, 4]].<br>
> Or is this an extension of v.7.1, that I am not aware of?<br>
><br>
> Regards,<br>
> Leonid<br>
><br>
> On Sun, Jan 31, 2010 at 2:55 AM, Patrick Scheibe <<br>
> <a href="mailto:pscheibe at trm.uni-leipzig.de">pscheibe at trm.uni-leipzi=
g.de</a>> wrote:<br>
><br>
> > Hi,<br>
> ><br>
> > I assume the only thing you miss is how to express a "sequen=
ce of<br>
> > numbers"? Just use Sequence[] :-)<br>
> ><br>
> > list=Range[20];<br>
> > Position[list, Sequence[11, 12, 13]]<br>
> ><br>
> > Cheers<br>
> > Patrick<br>
> ><br>
> > On Sat, 2010-01-30 at 07:12 -0500, JB wrote:<br>
> > > Hi,<br>
> > ><br>
> > > What is the most efficient way to find the position of the b=
eginning<br>
> > > of a sequence of numbers from a list?<br>
> > ><br>
> > > I found a couple of ways:<br>
> > ><br>
> > > find 3,4 in list={1,2,3,4,5};<br>
> > ><br>
> > > 1. pos=Intersection[Position[list,3],(Position[list=
,4])+1]<br>
> > ><br>
> > > 2. pos=Position[Partition[list,2,1],{3,4}]<br>
> > ><br>
> > > Are there other ways to do this?<br>
> > > What is the best way when dealing with large lists?<br>
> > ><br>
> > > Thanks,<br>
> > > JB<br>
> > ><br>
> ><br>
> ><br>
> ><br>
><br>
<br>
</div></div></blockquote><br></div><br>
--002354530710f4c28a047e794078--