MathGroup Archive 2012

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

Search the Archive

Re: pattern matching

  • To: mathgroup at
  • Subject: [mg128317] Re: pattern matching
  • From: Bill Rowe <readnews at>
  • Date: Sat, 6 Oct 2012 01:52:12 -0400 (EDT)
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:
  • Delivered-to:

On 10/5/12 at 2:52 AM, dnlsnd777 at (Daniel Sanders) wrote:

>Consider the following code:

>Count[Table[RandomInteger[], {n}], 1]/n, {n, 100, 1000, 10}], x_ <

>I want to count the number of times there are occurrences less than
>.5 but some how I am not specifying the right pattern.  Any
>suggestions on getting right?

You need to use PatternTest rather than just a pattern. That is:

In[13]:= MatchQ[.2, x_ < .5]

Out[13]= False

In[14]:= MatchQ[.2 , _?(# < .5 &)]

Out[14]= True

  • Prev by Date: ordering a group of symbolic operators
  • Next by Date: Re: Markers in list plot
  • Previous by thread: Re: pattern matching
  • Next by thread: Problem in solving nonlinear Differential Equation