From: Thomas Dowling on
Hello,

One way, perhaps:

fn[{x_, y_, z_}] :=
Select [subs3, FreeQ[#1, x] && FreeQ[#1, y] && FreeQ[#1, z] &]

In[35]= fn[subs3[[10]]]

Out[35]= {{2, 3, 6}, {2, 3, 7}, {2, 6, 7}, {3, 6, 7}}



Tom Dowling



On Fri, May 28, 2010 at 12:21 PM, S. B. Gray <stevebg(a)roadrunner.com> wrote:

> Hello:
>
> I have this line
>
> subs3 = Subsets[Range[numbr], {3}] which for numbr=7 gives subs3=
>
> {{1,2,3}, {1,2,4}, {1,2,5}, {1,2,6}, {1,2,7}, {1,3,4}, {1,3,5},
> {1,3,6}, {1,3,7}, {1,4,5}, {1,4,6}, {1,4,7}, {1,5,6}, {1,5,7},
> {1,6,7}, {2,3,4}, {2,3,5}, {2,3,6}, {2,3,7}, {2,4,5}, {2,4,6},
> {2,4,7}, {2,5,6}, {2,5,7}, {2,6,7}, {3,4,5}, {3,4,6}, {3,4,7},
> {3,5,6}, {3,5,7}, {3,6,7}, {4,5,6}, {4,5,7}, {4,6,7}, {5,6,7}}
>
> Given one of these sublists, say {1,4,5}, I want a nice way to delete
> all members of the subs3 list which have 1,4, or 5 in any one of the
> three positions. The reduced list in this example would be
> {{2,3,6}, {2,3,7}, {2,6,7}, {3,6,7}}.
>
> The way I'm doing it runs DeleteCases nine times. Is there a better way?
>
> Steve Gray
>
>
From: Leonid Shifrin on
Hi Steve,

Your test list:

In[1] :=
test = {{1, 2, 3}, {1, 2, 4}, {1, 2, 5}, {1, 2, 6}, {1, 2, 7}, {1, 3,
4}, {1, 3, 5}, {1, 3, 6}, {1, 3, 7}, {1, 4, 5}, {1, 4, 6}, {1, 4,
7}, {1, 5, 6}, {1, 5, 7}, {1, 6, 7}, {2, 3, 4}, {2, 3, 5}, {2, 3,
6}, {2, 3, 7}, {2, 4, 5}, {2, 4, 6}, {2, 4, 7}, {2, 5, 6}, {2, 5,
7}, {2, 6, 7}, {3, 4, 5}, {3, 4, 6}, {3, 4, 7}, {3, 5, 6}, {3, 5,
7}, {3, 6, 7}, {4, 5, 6}, {4, 5, 7}, {4, 6, 7}, {5, 6, 7}};

Here is one way using Complement:

In[2]:=
Select[test, Complement[#, Complement[#, {1, 4, 5}]] === {} &]

Out[2]=
{{2, 3, 6}, {2, 3, 7}, {2, 6, 7}, {3, 6, 7}}

Somewhat similar one using MemberQ:

In[3]:=
DeleteCases[test, x_ /; MemberQ[x, Alternatives @@ {1, 4, 5}]]

Out[3]=
{{2, 3, 6}, {2, 3, 7}, {2, 6, 7}, {3, 6, 7}}

Here is another one using patterns:

In[4]:=
With[{ptrn = Alternatives @@ {1, 4, 5}},
DeleteCases[test, {ptrn, _, _} | {_, ptrn, _} | {_, _, ptrn}]]

Out[4]=
{{2, 3, 6}, {2, 3, 7}, {2, 6, 7}, {3, 6, 7}}

The above pattern can be constructed programmatically:

In[5]:=
With[{ptrn = Alternatives @@ {1, 4, 5}},
DeleteCases[test,
Alternatives @@ NestList[RotateRight, {ptrn, _, _}, 2]]]

Out[5]= {{2, 3, 6}, {2, 3, 7}, {2, 6, 7}, {3, 6, 7}}



Regards,
Leonid



On Fri, May 28, 2010 at 3:21 PM, S. B. Gray <stevebg(a)roadrunner.com> wrote:

> Hello:
>
> I have this line
>
> subs3 = Subsets[Range[numbr], {3}] which for numbr=7 gives subs3=
>
> {{1,2,3}, {1,2,4}, {1,2,5}, {1,2,6}, {1,2,7}, {1,3,4}, {1,3,5},
> {1,3,6}, {1,3,7}, {1,4,5}, {1,4,6}, {1,4,7}, {1,5,6}, {1,5,7},
> {1,6,7}, {2,3,4}, {2,3,5}, {2,3,6}, {2,3,7}, {2,4,5}, {2,4,6},
> {2,4,7}, {2,5,6}, {2,5,7}, {2,6,7}, {3,4,5}, {3,4,6}, {3,4,7},
> {3,5,6}, {3,5,7}, {3,6,7}, {4,5,6}, {4,5,7}, {4,6,7}, {5,6,7}}
>
> Given one of these sublists, say {1,4,5}, I want a nice way to delete
> all members of the subs3 list which have 1,4, or 5 in any one of the
> three positions. The reduced list in this example would be
> {{2,3,6}, {2,3,7}, {2,6,7}, {3,6,7}}.
>
> The way I'm doing it runs DeleteCases nine times. Is there a better way?
>
> Steve Gray
>
>
From: Bill Rowe on
On 5/28/10 at 7:21 AM, stevebg(a)ROADRUNNER.COM (S. B. Gray) wrote:

>I have this line

>subs3 = Subsets[Range[numbr], {3}] which for numbr=7 gives subs3=

<output snipped>

>Given one of these sublists, say {1,4,5}, I want a nice way to
>delete all members of the subs3 list which have 1,4, or 5 in any one
>of the three positions. The reduced list in this example would be
>{{2,3,6}, {2,3,7}, {2,6,7}, {3,6,7}}.

>The way I'm doing it runs DeleteCases nine times. Is there a better
>way?

Here is one way

In[12]:= DeleteCases[subs3, _?(Intersection[{1, 4, 5}, #] != {} &)]

Out[12]= {{2, 3, 6}, {2, 3, 7}, {2, 6, 7}, {3, 6, 7}}


From: Peter Breitfeld on
"S. B. Gray" wrote:

> Hello:
>
> I have this line
>
> subs3 = Subsets[Range[numbr], {3}] which for numbr=7 gives subs3=
>
> {{1,2,3}, {1,2,4}, {1,2,5}, {1,2,6}, {1,2,7}, {1,3,4}, {1,3,5},
> {1,3,6}, {1,3,7}, {1,4,5}, {1,4,6}, {1,4,7}, {1,5,6}, {1,5,7},
> {1,6,7}, {2,3,4}, {2,3,5}, {2,3,6}, {2,3,7}, {2,4,5}, {2,4,6},
> {2,4,7}, {2,5,6}, {2,5,7}, {2,6,7}, {3,4,5}, {3,4,6}, {3,4,7},
> {3,5,6}, {3,5,7}, {3,6,7}, {4,5,6}, {4,5,7}, {4,6,7}, {5,6,7}}
>
> Given one of these sublists, say {1,4,5}, I want a nice way to delete
> all members of the subs3 list which have 1,4, or 5 in any one of the
> three positions. The reduced list in this example would be
> {{2,3,6}, {2,3,7}, {2,6,7}, {3,6,7}}.
>
> The way I'm doing it runs DeleteCases nine times. Is there a better way?
>
> Steve Gray
>

This may work, but I don't know if it's fast.

First create a pattern for the items to be deleted:

testform=Permutations[{1,4,5,_,_},{3}]

Then delete all elements matching testform:

DeleteCases[subs3,Alternatives @@ testform]

you get your result.

//Peter
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

From: J. Clarke on
On 5/28/2010 7:21 AM, S. B. Gray wrote:
> Hello:
>
> I have this line
>
> subs3 = Subsets[Range[numbr], {3}] which for numbr=7 gives subs3=
>
> {{1,2,3}, {1,2,4}, {1,2,5}, {1,2,6}, {1,2,7}, {1,3,4}, {1,3,5},
> {1,3,6}, {1,3,7}, {1,4,5}, {1,4,6}, {1,4,7}, {1,5,6}, {1,5,7},
> {1,6,7}, {2,3,4}, {2,3,5}, {2,3,6}, {2,3,7}, {2,4,5}, {2,4,6},
> {2,4,7}, {2,5,6}, {2,5,7}, {2,6,7}, {3,4,5}, {3,4,6}, {3,4,7},
> {3,5,6}, {3,5,7}, {3,6,7}, {4,5,6}, {4,5,7}, {4,6,7}, {5,6,7}}
>
> Given one of these sublists, say {1,4,5}, I want a nice way to delete
> all members of the subs3 list which have 1,4, or 5 in any one of the
> three positions. The reduced list in this example would be
> {{2,3,6}, {2,3,7}, {2,6,7}, {3,6,7}}.
>
> The way I'm doing it runs DeleteCases nine times. Is there a better way?

I'm just learning Mathematica myself so have no idea if this is a good
or bad way to do it, but:

Select[subs3, Intersection[{1, 4, 5}, #] == {} &]

will I think do what you're asking.