# Choosing sets from Subsets[list] part 2

Piggybacking off of this question, say if I wanted to exclude sets which weren't the union of elements of the list of lists.

For example:

S={1,2,3,4,a,b,c,d}
exclude.sets.containing={1,2,3,4}
L={{a,1,4},{b,1,2},{c,2,3},{d,3,4}}.


Then f[S,exclude.sets.containing,L]={{a,1,4},{b,1,2},{c,2,3},{d,3,4},{a,b,1,2,4},{a,d,1,3,4},{b,c,1,2,3},{c,d,2,3,4}}

As you can see, each element of f[S,exclude.sets.containing,L] is generated by the union of elements of L, but does not contain {1,2,3,4}, which would be a larger output. Any help would be greatly appreciated!

There are more elegant ways, but this works:

myL = {{a, 1, 4}, {b, 1, 2}, {c, 2, 3}, {d, 3, 4}, {a, b, 1, 2,
4}, {a, d, 1, 3, 4}, {b, c, 1, 2, 3}, {c, d, 2, 3, 4}};

myFullList =
Flatten[Table[
Union[myL[[i]], myL[[j]]],
{i, Length[myL]}, {j, Length[myL]}], 1];

Select[myFullList, Not[SubsetQ[#, {1, 2, 3, 4}]]  &]


(* {{1, 4, a}, {1, 2, 4, a, b}, {1, 3, 4, a, d}, {1, 2, 4, a, b}, {1, 3, 4, a, d}, {1, 2, 4, a, b}, {1, 2, b}, {1, 2, 3, b, c}, {1, 2, 4, a, b}, {1, 2, 3, b, c}, {1, 2, 3, b, c}, {2, 3, c}, {2, 3, 4, c, d}, {1, 2, 3, b, c}, {2, 3, 4, c, d}, {1, 3, 4, a, d}, {2, 3, 4, c, d}, {3, 4, d}, {1, 3, 4, a, d}, {2, 3, 4, c, d}, {1, 2, 4, a, b}, {1, 2, 4, a, b}, {1, 2, 4, a, b}, {1, 3, 4, a, d}, {1, 3, 4, a, d}, {1, 3, 4, a, d}, {1, 2, 3, b, c}, {1, 2, 3, b, c}, {1, 2, 3, b, c}, {2, 3, 4, c, d}, {2, 3, 4, c, d}, {2, 3, 4, c, d}} *)

• Thank you very much, this works wonderfully! Jan 19, 2016 at 5:33