Re: Pattern Matching

• To: mathgroup at smc.vnet.net
• Subject: [mg58250] Re: Pattern Matching
• From: "dkr" <dkrjeg at adelphia.net>
• Date: Fri, 24 Jun 2005 02:50:21 -0400 (EDT)
• References: <d9e0bc\$g6i\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```As I understand it, you want to start with a list, taking the first
element of the list as the starting point. Then you want to extract the
first element remaining in the list that is = to this starting point
by at least 2.  Then treating this extracted element as a new starting
point, you want to extract the first element remaining in the list that
is = this new starting point by at least 2.  Then take this last
element extracted, treat it as a new starting point and so on. If this
is what you want, the following should work:

In[13]:=
{0,-1,0,-1,-2,-3,-4,-3,-4,-5}//.{e___List,a_Integer,b___,c_,d___}/;(c<=(a-2)):>
{e,{c},c,d}/.{x___List,__Integer}:>Flatten[{x}]

Out[13]={-2,-4}

(Note that by default Mathematica's pattern matcher will attempt to find the
shortest sequence to match b, and hence no elements of b will satisfy
b<=(a-2).  The sequence of lists at the beginning of the pattern are
used to store the extracted elements, with the initial match for e
being null. )

```

• Prev by Date: Module command acting funny...
• Next by Date: Documentation
• Previous by thread: Re: Pattern Matching
• Next by thread: Re: Pattern Matching