[Math] Calculating possible combinations for 1-3 digit code

combinatoricspermutations

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

Best Answer

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.

Related Question