From: S. B. Gray on
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: Bob Hanlon on

subs3[numbr_Integer] :=
Subsets[Range[numbr], {3}]

data = subs3[7];

Select[data, FreeQ[#, 1 | 4 | 5] &]

{{2, 3, 6}, {2, 3, 7}, {2, 6, 7},
{3, 6, 7}}

Cases[data, _?(FreeQ[#, 1 | 4 | 5] &)]

{{2, 3, 6}, {2, 3, 7}, {2, 6, 7},
{3, 6, 7}}


Bob Hanlon

---- "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: Adriano Pascoletti on
Some possible solutions:

In[1]:= L = {{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}};
In[2]:= Cases[L, x_ /; FreeQ[x, 1 | 4 | 5]]
Out[2]= {{2, 3, 6}, {2, 3, 7}, {2, 6, 7}, {3, 6, 7}}
In[3]:= Select[L, Intersection[#1, {1, 4, 5}] === {} & ]
Out[3]= {{2, 3, 6}, {2, 3, 7}, {2, 6, 7}, {3, 6, 7}}
In[4]:= DeleteCases[L, x_ /; ! FreeQ[x, 1 | 4 | 5]]
Out[4]= {{2, 3, 6}, {2, 3, 7}, {2, 6, 7}, {3, 6, 7}}
In[6]:= Select[L, Complement[#1, {1, 4, 5}] === #1 & ]
Out[6]= {{2, 3, 6}, {2, 3, 7}, {2, 6, 7}, {3, 6, 7}}


Adriano Pascoletti

2010/5/28 S. B. Gray <stevebg(a)roadrunner.com>

> 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: Raffy on
On May 28, 4:21 am, "S. B. Gray" <stev...(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

If you know the set ahead of time, you can just construct the desired
result:
Subsets[Complement[Range[7], {1,4,5}], {3}]

From: David Skulsky on
On May 28, 4:21 am, "S. B. Gray" <stev...(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

Here's one way:

In[29]:= Select[subs3, (Length[Intersection[#, {1, 4, 5}]] == 0) &]

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