Given multiple sets, e.g. s1={2,3,7}
, s2={1,2,4,7,8}
and s3={4,7}
, a Venn diagram visualizes each set by a closed curve and set elements which are either inside or outside the curve's perimeter, depending on whether they are element of the set or not. Because all set elements appear only once in the Venn digram, the curves representing each set need to overlap if an element is present in more than one set. We call each such overlapping a cell of the Venn diagram.
This explanation might be a bit confusing, so let's have a look at an example.
Example
A Venn diagram for sets s1
, s2
and s3
could look like this:
The cells of this Venn diagram are (read from top to bottom, left to right) {1,8}
, {2}
, {7}
, {4}
, {3}
, {}
and {}
.
In practice, one commonly encounters only Venn diagrams of two or three sets, because the representation of Venn diagrams of four or more sets is not very clear. However they do exist, e.g. for six sets:
CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=1472309
The Task
Given a non-empty set of sets of positive integers in any reasonable representation, return the set of cells of the input sets' Venn diagram. Specifically, no graphical representation is needed.
- You may write a full program or a function.
- You may return as many empty sets as there are empty cells (i.e. a list of all cells) instead of just one empty set (i.e. the set of cells).
- Some reasonable ways of input for the above example include but are not limited to
{{2,3,7},{1,2,4,7,8},{4,7}}
,[[2,3,7],[1,2,4,7,8],[4,7]]
,"2,3,7;1,2,4,7,8;4,7"
or"2 3 7\n1 2 4 7 8\n4 7"
. If in doubt whether your chosen input format is acceptable, feel free to ask in a comment. - Your output format should match your input format, if possible. Note that this rule requires your format to be able to unambiguously display empty sets.
- This is code-golf, so try to use as few bytes as possible in the language of your choice. In order to encourage competition per language instead of between languages, I won't accept an answer.
Test Cases
Here are some inputs along with possible outputs:
input -> output
{{2,3,7},{1,2,4,7,8},{4,7}} -> {{1,8},{2},{7},{4},{3},{}} (or {{1,8},{2},{7},{4},{3},{},{}})
{{1,2,3},{4,5,6},{7,8,9}} -> {{1,2,3},{4,5,6},{7,8,9},{}}
{{}} -> {{}}
{{1,2,3},{1,2}} -> {{1,2},{3},{}}
{{4,3,8},{1,2,9,3},{14,7,8,5},{6,11,3,8},{10},{9,4,3,7,10}} -> {{6,11},{10},{4},{3},{8},{5,14},{1,2},{9},{7},{}}
{{2,3,4,7},{},{1,3,7,5,6},{2,3,7,5},{7,2,4,3,6},{1,4,5}} -> {{},{4},{2},{7,3},{1},{6},{5}}
{{1,2,3,4},{1,2,5,6},{1,3,5,7}} -> {{4},{3},{2},{1},{6},{5},{7}}
{{1,2,3},{4,5,6},{7,8,9},{},{},{},{}}
? \$\endgroup\$