In school, we often solve problems involving set sizes. Here are five examples:
In a room, there are four people wearing a hat and/or with glasses. Three are wearing a hat and three are wearing glasses. How many people are wearing both hat and glasses?
In a school, there are six teachers of math, four teachers of history and no teachers of other disciplines. Given that there are two teachers who teach both math and history how many teachers are there in this school?
Given that the cardinality of set A is 60, the cardinality of set B is 360 and the cardinality of the union of A and B is 400, what is the cardinality of the intersection of A and B?
Given that #A=10, #(A∪B)=20 and #(A∩B)=2 what is #B?
The size of set B is 23. The size of the union of A and B is 45. The size of the intersection of A and B is 12. What is the size of set A?
The solution to these problems involve a mathematical relation between the sizes of sets, their intersection and union. Write a program that is able to solve these kinds of exercises so you do not need to solve them manually ever again.
Each line of input will contain four items: the number of elements in the first set; the number of elements in the second set; the number of elements in both sets; and the number of elements in either of the sets. In symbolic terms: #A, #B, #(A∩B) and #(A∪B). Three of these will be integer values, one will be an interrogation mark.
For each line of input, your program should produce a line of output with the corresponding missing value: #A, #B, #(A∩B) or #(A∪B).
3 3 ? 4 6 4 2 ? 60 360 ? 400 10 ? 2 20 ? 23 12 45
2 8 20 12 34
try first: set-ui bool-and-or
try also: set-calc
Copyright © 2020-2022 Rudy Matela
All rights reserved