Other than doing this:
from itertools import combinations
def brute_force(x):
for l in range (1,len(x)+1):
for f in list(combinations(range(0,len(x)),l)):
yield f
x = range(1,18)
len(list(brute_force(x)))
[out]:
131071
How could I mathematically calculate the number of all possible combinations?
Is there a way to do it computationally without enumerating the possible combinations?
Always there is 2n−1 non-empty subset of set
{1,...,n}
.For example consider the list
['a','b','c']
:That the length of our list is 3 so we have 23-1=7 combinations.
And for a
range(10)
:Note if you want to count the empty subset you can just use
2^n
.Actually at a mathematical perspective :
and for all combinations :