Calculate combinations

combinations

I've developed a PHP script that calculates the sum of a series of numbers in various combinations and compares the result with a given total value.
This is already working, but the problem is that this calculation can take months, maybe years!
To try to at least predict the time that will be spent, I would like to do a calculation to predict the total amount of possible combinations.

For exemplo, if I have a series with just 5 numbers:

1 ; 2 ; 3 ; 4 ; 5

I would like to calculate how many combinations are possible between them. Important:

  1. The same number will not be repeated in a combination, ie, (2; 3; 2).
  2. It would be interesting to know the total combinations by level, for example, total by 2 combined numbers, total by 3 combined numbers and so on.

enter image description here

Could someone help me with this formula?

Best Answer

From a comment by Mike Earnest:

$2^n - 1$. Can you see why?