MathGroup Archive 2011

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

Search the Archive

Re: Pattern matching in lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116120] Re: Pattern matching in lists
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Thu, 3 Feb 2011 05:26:28 -0500 (EST)

----- Original Message -----
> From: "Harvey P. Dale" <hpd1 at nyu.edu>
> To: mathgroup at smc.vnet.net
> Sent: Wednesday, February 2, 2011 5:07:02 AM
> Subject: [mg116096] Pattern matching in lists
> MemberQ easily tests whether a single integer appears in a list
> of integers. Suppose, however, that I want to test not for a single
> integer but for two or more consecutive integers, e.g., to see whether
> {1,4,6} is a member of {1,3,2,6,5,1,4,6,3,9}. I can do this by
> converting both lists into strings and then using string-matching
> functions, but is there some way of doing it directly without that
> conversion?
> 
> Thanks.
> 
> Harvey
> 
> Harvey P. Dale
> [...]

In[7]:= Or @@ 
 ListCorrelate[{1, 4, 6}, {1, 3, 2, 6, 5, 1, 4, 6, 3, 9}, {-1, 1}, {},
   Equal, And]

Out[7]= True

I've no idea why all the optional arguments to ListConvolve/Correlate were not made into Options. This strikes me as a particularly flawed aspect in the design of these otherwise excellent functions.

Daniel Lichtblau
Wolfram Research





  • Prev by Date: Re: Mystifying Scoping of Piecewise Variable?
  • Next by Date: Re: Plot artifact of NDSolve result
  • Previous by thread: Re: Pattern matching in lists
  • Next by thread: Re: Pattern matching in lists