Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2009

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

Search the Archive

Re: find subsets

  • To: mathgroup at
  • Subject: [mg104725] Re: [mg104694] find subsets
  • From: Bob Hanlon <hanlonr at>
  • Date: Sun, 8 Nov 2009 06:43:38 -0500 (EST)
  • Reply-to: hanlonr at

Ns = Subsets[{a, b, c, d, e}, {3}];


Ns == KSubsets[{a, b, c, d, e}, 3]


Cases[Ns, {___, b, ___}]

{{a, b, c}, {a, b, d}, {a, b, e}, {b, c, d}, {b, c, e}, {b, d, e}}

% == Cases[Ns, _?(! FreeQ[#, b] &)]


%% == Select[Ns, ! FreeQ[#, b] &]


Cases[Ns, {___, b, c, ___}]

{{a, b, c}, {b, c, d}, {b, c, e}}

% == Cases[Ns, {___, b, ___, c, ___}]


%% == Cases[Ns, _?(! FreeQ[#, b] && ! FreeQ[#, c] &)]


Bob Hanlon

---- r_poetic <radford.schantz at> wrote: 

here is a quick question from a novice.

First, generate a list of subsets using Subsets or KSubsets

Ns = KSubsets[{a,b,c,d,e},3] = {{a,b,c},{a,b,d},{a,b,e},{a,c,d}, etc.}

How can one infer from that list a list of its members that contain
given elements, e.g. a list of members that contain b, or those that
contain both b and c? For illustration:

Some_function[Ns, b and c] = { {a,b,c},{b,c,d},{b,c,e}}

I keep thinking there must be a direct way to do this using Select or
some other function?

  • Prev by Date: Re: Finding Clusters
  • Next by Date: Re: What is going on!?!
  • Previous by thread: Re: find subsets
  • Next by thread: Re: find subsets