Sign up ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have three variables in a programming function, and a 4th variable depends on these. I have to test the dependent variable against all combinations of the three variables:

  • Var A: 2 possible values
  • Var B: 3 possible values
  • Var C: 5 possible values

The order of the three variables is not important. How can I find the number of possible combinations of these three variables, so that I know how many tests would need to be written?

Note: I have asked a further question regarding this:

Now I know that there are 30 combinations of these three variables (2x3x5), but how do I draw this in table form?

If each variable was binary, I could draw a truth table: 000, 001, 010 etc. But is there an equivalent system for the combination I have detailed here?



share|cite|improve this question
Brian already answered, but from a programming standpoint, are you talking about unit testing your function or a 30 case switch statement. If you're talking about a 30 case switch statement, you might consider refactoring that function as it'll likely be a maintenance nightmare. – D. Patrick May 15 '12 at 13:21
I wanted to know the combinations for unit testing purposes.. .good point though:) – Brian Bishop May 16 '12 at 13:53

1 Answer 1

up vote 5 down vote accepted

For each of the $2$ possible values of $A$ there are $3$ possible values of $B$; that makes $2\cdot 3=6$ possible combinations, as you can see by setting up a $2\times 3$ grid showing all $6$ combinations.

$$\begin{array}{|c|c|c|c|}\\ \hline &b_1&b_2&b_3\\ \hline a_1&(a_1,b_1)&(a_1,b_2)&(a_1,b_3)\\ \hline a_2&(a_2,b_1)&(a_2,b_2)&(a_2,b_3)\\ \hline \end{array}$$

Each of these $6$ combinations can in turn be combined with any of the $5$ possible values of $C$, so the same reasoning gives you a total of $6\cdot5=30$ combinations.

The general principle, sometimes called the multiplication or Chinese menu principle, is that if you have a sequence of $n$ choices to be made, and the $k$-th choice can be make in $m_k$ ways independently of the other choices, then the total number of ways to make the combined choice is $$m_1m_2m_3\dots m_n\;,$$ the product of the numbers of ways to make the individual choices.

share|cite|improve this answer
Thanks, the detailed explanation is appreciated.... it seems intuitive, but I didnt want to rely on my intuitions alone:-) – Brian Bishop May 15 '12 at 10:54
I have asked a question on a similar vein... regarding how to draw a table for the combinations described above.… – Brian Bishop Nov 2 at 10:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.