Calculate all possible combinations of 1 to n variables taking 2 values

combinatorics

I am trying to calculate all possible combinations of n variables taking 2 values (1, 0) with the number of variables being allowed to vary between 1 and n. E.g.:

For 1 variable (A), the number is 2.

A
0
1

For 2 variables (A, B), the number is 8.

A B
1
  1
0 
  0
1 1
0 1
1 0
0 0

For 3 variables (A, B, C), I think the number is 26 (correct me if I am wrong).

A B C
1
  1
    1 
0
  0
    0
1 1
  1 1
1   1
0 0
  0 0
0   0
1 0
1   0
0 1
  1 0
0   1
  0 1
1 1 0
0 1 0
1 0 0
0 0 0
1 1 1
0 1 1
1 0 1
0 0 1

I did the same exercise with 4 variables (A, B, C, D) and I came to 80 combinations (again, correct me if I am wrong). I will not list them here because the minimal illustration above should suffice.

I tried to find the formula giving the total number of possible combinations but I did not succeed. Could someone help me?

Best Answer

You have three choices for each of the $n$ variables: $0$, $1$, or omit. That would give you $3^n$ choices. However, in your lists, you are omitting the case where all omits occurs, which leaves you with $3^n - 1$ possible outcomes when you have $n$ variables.

Related Question