A permutation is a calculation of how many ways a set can be represented. This is a simple factorial of the number of the entire set.

Meaning if we had a set of values:

a, b, c
factorial(3) # 3!
> 6          # 3 * 2 * 1

However the formula changes as we get into more complex problems. Consider this example on BetterExplained.com:

# we have 8 contestants:
1: Alice
2: Bob
3: Charlie
4: David
5: Eve
6: Frank
7: George
8: Horatio

# How many ways can we award a 1st, 2nd and 3rd place price among eight contestants? 

P(n,k) = n! / (n-k)!

In the above equation n would be 8 (8 contestants) and k is 3 (three outcomes of Gold, Silver or Bronze medals.) That leaves us with 8! / 5!

This results in 336 possible permutations!

The above equation works for problems where repetition is not allowed.

Permutations with Repetition

Looking at the password example from Pierian Data’s Udemy course, we have a problem of determining how many 4 digit license plates can be created using any of the 26 letters of the English alphabet + the numbers 0-9. That’s a total of 36 characters used in a password.

In this case we allow the permutation to take a repeating character, like 5555 or aaaa or acda. The equation is simply:

# n^k
n**k     # where k is the subset (4) of the population (36)
>>> 1679616


No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *