I have a little mathematic problem. I have bar code with 3 types of black (x, y, z) lines and 2 types of white lines (w, v). There are 12 black lines and 11 white lines. And black and white lines alternate like B, W, B, W, B.. 2 black lines are outside.

Now should I find how many codes I can make from it when every type of line will be used minimaly ones. It means that I will have minimally one x, minimally one y, minimally one z, minimally one w and minimally one v.

For calculation I used Inclusion–exclusion principle. So I find how many black sequence don´t have minimally one from every type and how many sequence don´t have minimaly one from white type.

The numbers:

exists 3^12 possibilites how get black sequence without any condition

exists 2^11 possibilites how get white sequence without any condition

exists 12 285 possibilites when minimally one type of black is missing

exists 2 possibilites when minimally one type of white is missing

now comes the problem. The number of codes I can get when I multyply the 3^12 * 2^11 and subtract (12 285 * 2)? (the result = 1 088 366 598)

(3^12 * 2^11) - (12 285 * 2) = 1 088 366 598

Or should I sooner substract the numbers for black sequence 3^12 - 12 285 and then multyply it with white sequence (2^11 - 2)? (result = 1 062 193 176)

(3^12 - 12 285) * (2^11 - 2) = 1 062 193 176

Which method is correct and why?

Thanks for your advices.

Notes: I was counting it for black and white sequence separately


1 Answer 1


Since the black and white issues are separate, you should remove the failing cases for each before the multiplication. Otherwise, you will erroneously be counting cases where one of the black and white patterns fail and the other colour's patterns pass.

So using inclusion-exclusion, you should get

$$\left(3^{12}-3 \times 2^{12} +3\times 1^{12} -0^{12}\right)\left(2^{11}-2 \times 1^{11} +0^{11}\right)$$

which, as you have calculated, is $1062193176$.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .