Find required card combination to add up to a specific number of colors Assume I got unlimited supply of cards: there exist three kinds, red cards, blue cards and ones that count for both red and blue. I now want to calculate how many of each of these three cards I need to meet a certain number of blue and red cards, while providing the number of cards to use in total. Example for (hopefully) more clarity:


*

*total number of cards to use: 22

*number of red cards to meet: 14

*number of blue cards to meet: 16


In this case, I would need:


*

*8 cards that count for both blue and red

*6 red cards

*8 blue cards


This combination of cards adds up to 22 in total while providing 14 red and 16 blue cards, since 8 of our cards count for both. For this simple example, I can easily calculate that in my head. But for bigger ones, how would I calculate this? Is there like a formula I could create out of this?
How would such a scenario work out with three colors? So now there is a card that counts for all three colors, three cards that count for color the pairs (red/blue, red/green and blue/green) and the single colored cards.
 A: Let


*

*$a$ be the number of cards needed that count for red

*$b$ be the number of cards needed that count for blue

*$c$ be the total number of cards


These three values fall very neatly into a Venn diagram:

Then the total number of cards needed that count for both red and blue is, by the inclusion-exclusion principle, $a+b-c$. From there we can work out the number of red cards ($a-(a+b-c)=c-b$) and the number of blue cards ($c-a$).

For three colours it's much the same thing, with three sets in the Venn diagram. You also need, in addition to the number of cards that count for each one of the three colours $c_r,c_g,c_b$ and the total $N$, the number of cards that count for each combination of two of the three colours $c_{rg},c_{gb},c_{br}$, otherwise the solution may not be unique.
We get the number of three-coloured cards $c_{rgb}$ from the inclusion-exclusion principle:
$$c_r+c_g+c_b-c_{rg}-c_{gb}-c_{br}+c_{rgb}=N$$
$$N-(c_r+c_g+c_b-c_{rg}-c_{gb}-c_{br})=c_{rgb}$$
Then the numbers of cards with exactly two colours – $c_{rg}'$ for example is the number of cards with red and green and not blue:
$$c_{rg}'=c_{rg}-c_{rgb}$$
$$c_{gb}'=c_{gb}-c_{rgb}$$
$$c_{br}'=c_{br}-c_{rgb}$$
Finally the numbers of cards with exactly one colour:
$$c_r'=c_r-c_{rg}'-c_{br}'-c_{rgb}$$
$$c_g'=c_g-c_{gb}'-c_{rg}'-c_{rgb}$$
$$c_b'=c_b-c_{br}'-c_{gb}'-c_{rgb}$$
