How many combinations for a 5 digit code using 3 numbers. Can anyone please help here?
I have inherited a strange looking safe with only numbers 1 2 and 3.
The code to open it is 5 digits and the code uses all three numbers at least once.
Is there some formula I can apply to list all the combinations?
Thanks

If there were no restrictions, the number of five digit codes that could be formed with the digits 1, 2, 3 would be $3^5$ since there are three ways to choose each of the five digits.  From these, we must exclude those codes in which fewer than three digits are used.  
There are $\binom{3}{1}$ ways to exclude one of the digits and $2^5$ ways to form a five digit code using two numbers.  Thus, there are 
$$\binom{3}{2}2^5$$ 
codes that use at most two numbers.  
When we exclude those codes that have at most two numbers, we exclude those codes that use only one number twice, once each when we exclude the other two numbers.  For instance, we exclude 11111 when we exclude those codes that do not include a 2 and exclude it again when we exclude those codes that do not include a 3. Therefore, we must add those codes that use only one of the numbers so that we only exclude them once.  
There are $\binom{3}{2}$ ways to exclude two of the digits and $1^5$ ways to form a five digit code using one number.  Thus, there are 
$$\binom{3}{2}1^5$$ 
codes that use one number.  
By the Inclusion-Exclusion Principle, the number of five digit codes using each of the digits 1, 2, and 3 at least once is 
$$3^5 - \binom{3}{1}2^5 + \binom{3}{2}1^5$$
