MathGroup Archive 2011

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

Search the Archive

Re: Help with Delete cases

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116269] Re: Help with Delete cases
  • From: KenR <ramsey2879 at msn.com>
  • Date: Wed, 9 Feb 2011 02:10:15 -0500 (EST)
  • References: <iir4h6$6kh$1@smc.vnet.net>

On Feb 8, 5:05 am, Bob Hanlon <hanl... at cox.net> wrote:
> list = Range[3003];
>
> sol1 = With[{m = 5, p = 7},
>    DeleteCases[list, _?(Mod[# - m (m + 1)/2, p] == 0 &)]];
>
> sol2 = With[{m = 5, p = 7},
>    Cases[list, Except[_?(Mod[# - m (m + 1)/2, p] == 0 &)]]];
>
> sol3 = With[{m = 5, p = 7},
>    Cases[list, _?(Mod[# - m (m + 1)/2, p] != 0 &)]];
>
> sol4 = With[{m = 5, p = 7},
>    Select[list, Mod[# - m (m + 1)/2, p] != 0 &]];
>
> sol5 = With[{m = 5, p = 7},
>    list //. _?(Mod[# - m (m + 1)/2, p] == 0 &) :> Sequence[]];
>
> sol1 == sol2 == sol3 == sol4 == sol5
>
> True
>
> 3003 - Length[sol1]
>
> 429
>
> Bob Hanlon
>
> ---- KenR <ramsey2... at msn.com> wrote:
>
> =============
> I have a list= Range[3003]  I want todeletecasesof n = m(m+1) mod P
> from the list, butDeletecasesonly deletescasesmatching a pattern,
> i.e.
>
> list = DeleteCases[list,Mod[N - m(m+1)/2,P] = 0] will definitely not
> work.  I want to keep list, as the same identifier, throughout since
> this is within a looping process. Any suggestions?

I read all of the responses to my post and greatly appreciate the many
ideas that were provided to me for adding a logical test to the
DeleteCases function. I think I have more than enough to complete my
task thanks to all that posted. Bob Hanlon's post was right on and
Sjoerd C. de Vries and others gave me a name for the Select  _?  and /
functions so I could look up more documentation which I did not find
under DeleteCases or Cases.  Thanks to all that posted.  I am
definitely glad that I joined this group. In a few days I will receive
a few books on Mathematica and hope my posts will be less demanding or
vague in their nature.


  • Prev by Date: Re: Generated parameters
  • Next by Date: Re: ContourPlot and lines vrs. 8.0
  • Previous by thread: Re: Help with Delete cases
  • Next by thread: Using Mathematica to Grab RSS Feeds