# counting sets

• December 10th 2009, 01:58 PM
ruleworld
counting sets

I own twenty-three programming textbooks. Nine of them cover Java, ten cover Python, and ten cover C++. Three cover Java and C++, one covers Python and C++, and two cover Python and Java. How many cover only Python?
• December 10th 2009, 03:00 PM
emakarov
This can be solved using Inclusion–exclusion principle (IEP). Let us denote the sets of books covering each language as J, P, and C. The set of all books is $J\cup P\cup C$, though these three sets intersect invarious ways. By IEP,

$|J\cup P\cup C|=|J|+|P|+|C|-|J\cap P|-|J\cap C|-|P\cap C|+|J\cap P\cap C|$

You know the left-hand side and all but the last term in the right-hand side, so you can find the last one.

Next, Let $PO$ be the set of books about Python only. Then $P=PO\cup (P\cap C)\cup (P\cap J)$. Again we have the union of three sets. Apply IEP to this union. This will allow you to find $|PO|$.

It may also help looking at the three-set diagram on the Wikipedia page given above.
• December 10th 2009, 03:41 PM
ruleworld
Thanks that really helped.