How to find the number of codes of n length and m number of possible digits. (Combinatorics)

44 Views Asked by At

I need a simple equation where the following rules apply:

The answer must be the total amount of possible codes.
Codes are made up of m number of possible digits.
In each code every digit needs to be used at least once.
A code may have repeated digits.

I would like to use the following variable names

c is the number of codes
m is the number of possible digits
n is the length of the combination

for: n=3 m=3

$^mP_n$ works because it simplifies to 3! or 6

but in cases where n<m it would break because $^-Z!$ is impossible

I did try using Chat-GPT however it is insisting that the answer is $c = m^n - (m-1)^n$ which doesn't work for any inputs I give it. With that equation I tried $m = 3 = n$

$c = m^n - (m-1)^n$

$c = 3^3 - (3-1)^3$

$c = 27 - 2^3$

$c = 27 - 8$

$c = 19$

Any help would be greatly appreciated.

Thank you.