# How to calculate combinations of multiple variables which can assume multiple values

I have 3 variables (A,B,C); each variable can assume 3 different values (1,2,3) . I want to calculate ho many combinations there are which follow this rule:

let's fix A1, then cycle on all the others variables which can assume 3 values each; then let's move on to A2 and calculate again all the combinations by cycling over the 2 remaining variables (which can assume 3 values each); same thing for A3. Once I am done with A I repeat the same process with B and so on. The constrain is that the combinations must repeat only once over all: in fact if I fix A1 and the combination I get is (A1 B3 C2 ), then when I fix for example B3 I must not count (A1 B3 C2) because it has been already found before.

So what I need is the mathematical formula that allows me to do this calculation with a generic number of variables which can assume a generic number of values

## 1 Answer

For clarification, I am assuming we are keeping it as an ordered pair (A,B,C) for whatever ABC happens to be. (I.e. we are never concerned about a permutation of the letters such as (B,A,C))

You have 3 choices for the result of A, three choices for the result of B, and 3 choices for the result of C. By multiplication principle it is then $3\cdot 3\cdot 3 = 3^3=27$.

In general, if you have $r$ variables, each of which can take $n$ values, (I.e. we have letters $(A_1, A_2,\dots, A_r)$ each of which can be any number from $\{1,2,\dots,n\}$, there will be $n\cdot n\cdots n = n^r$ total possibilities.

Even more generally, if you have $r$ variables, the $i^{th}$ of which can take on $n_i$ values, you will have $\prod\limits_{i=1}^r n_i$ number of possibilities.

For a simple example, you go to an icecream shop and would like to get a sundae. A sundae consists of one flavor of icecream and any combination of toppings you'd like (some, all, or none). If there are five flavors of icecream and four available toppings, how many different ice cream sundaes are possible? Break it up via multiplication principle to first ask the question how many flavors of icecream there are (flavor 1, flavor 2,...). Then to ask the question if you use the first topping (yes or no), yes or no to the second topping, yes or no to the third...

This is exactly the same problem as how many possibilities exist for (A,B,C,D,E) if $A\in\{1,2,3,4,5\}$, and each of B through E are either 1 or 2. If for example, B is 1, then don't use that topping.

There are then $5\cdot 2\cdot 2\cdot 2\cdot 2=80$ possible sundaes.

• Thank you very much!! Your answer is super helpfull!!! Feb 21, 2015 at 18:32
• To add a bit more complexity to this answer (hopefully not too far away from when the question was asked), but how does this change if, say variable A can be a floating-point number?
– erik
May 3, 2016 at 2:54
• @espais it doesn't change at all. All that matters are the number of options for each. If some of those options are irrational numbers, or even not numbers at all, it doesn't matter May 3, 2016 at 3:00
• Regarding your first sentence in the answer, isn't it called a tuple, not an ordered pair Sep 4, 2022 at 18:59
• @Hexatonic not that it much matters, but if I were to rewrite it today I would have used the phrase "ordered triple". In naming things, 2 - ordered pair, 3 - ordered triple, 4 - ordered quadruple, 5 - ordered quintuple, and so on... For size $n$ that would be an ordered $n$-tuple. These triples, quadruples, and so on are collectively referred to as tuples, the word tuple by itself does not imply the size. So, yes... tuple would have been a correct word to use. So is ordered triple. Yes, I had made a typo at the time in using pair instead of triple Sep 6, 2022 at 11:46