# Calculating possible combinations for 1-3 digit code

I have been researching a lot on permutations and calculating total numbers of combinations of certain array lengths allowing certain characters. However, all the equations used to do this only consider one length of array. I will show an example of what I mean below:

Let's assume I had a 3 digit pass code on my phone and it allowed me to enter the numbers 1-5. The following combinations would be possible:

{1,2,3} {1,2,4} {1,2,5} {1,3,4} {1,3,5} {1,4,5} {2,3,4} {2,3,5} {2,4,5} {3,4,5}

However, I would like to be able to include the combinations of pass code lengths of 1 and 2 as well as three (numbers up to 3).

{1} {2} {3} {1,2} {1,3} {2,3} {1,2,3} etc.

Is there and equation that can calculate the total number of possibilities for the second example.

Thanks

Use the formula for permutations $\frac{n!}{(n-k)!}$ where $!$ is the factorial symbol.

So $n! = n\times (n-1) \times (n-2)\times \cdots 1$

$0! = 1$ as per definition.

Thus $P(n,k) = \frac{n!}{(n-k)!}$

Then for your example: $$P(4,1) + P(4,2) + P(4,3) + P(4,4)$$

$$\frac{4!}{3!} + \frac{4!}{2!} + \frac{4!}{1!} + \frac{4!}{0!}$$

$$= \frac{4}{1} + \frac{4\times 3}{1} + \frac{4\times 3\times 2}{1} + \frac{4\times 3\times 2 \times 1}{1}$$

I'll leave the final answer for you.

You can sum up for $n=1, n=2, ...$ :

$3$ possibilities for n=1

$3*2$ possibilites for n=2

$5*4*3$ possibilities for n=3

You can just sum up the different combinations of length $1$, $2$ and $3$.

Assuming one can use a number multiple times in a pass code. The number of combinations of codes of length $1$ is $5$, the number of combinations of length $2$ is $5*5=25$ and the number of combinations of length $3$ is $5*5*5=125$.

Hence, the total number of combinations is $5+25+125=155$.