Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #15909 > unrolled thread

Re: Pattern matching in lists

Started byBob Hanlon <hanlonr@cox.net>
First post2011-02-03 10:26 +0000
Last post2011-02-03 10:26 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Pattern matching in lists Bob Hanlon <hanlonr@cox.net> - 2011-02-03 10:26 +0000

#15909 — Re: Pattern matching in lists

FromBob Hanlon <hanlonr@cox.net>
Date2011-02-03 10:26 +0000
SubjectRe: Pattern matching in lists
Message-ID<iidvrq$bf3$1@smc.vnet.net>
dataT = {1, 3, 2, 6, 5, 1, 4, 6, 3, 9};

dataF = {1, 3, 2, 6, 5, 1, 3, 6, 3, 9};

target = {1, 4, 6};

MemberQ[Partition[#, 3, 1], target] & /@
 {dataT, dataF}

{True, False}

# /. {{s___, Sequence @@ target, f___} -> True,
    {__} -> False} & /@ {dataT, dataF}

{True, False}


Bob Hanlon

---- "Harvey P. Dale" <hpd1@nyu.edu> wrote: 

=============
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.

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web