1
$\begingroup$

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!

$\endgroup$

1 Answer 1

2
$\begingroup$

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}} *)

$\endgroup$
1
  • $\begingroup$ Thank you very much, this works wonderfully! $\endgroup$
    – jix816
    Jan 19, 2016 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.