[Math] 4-digit password with unique digits not in ascending or descending order

combinatoricsdiscrete mathematicspermutations

I need to calculate how many possible passwords there are if each password is 4 digits long, using the digits 0-9. All digits in the password must be unique, and cannot all be neither increasing nor decreasing. For example “3569” is not allowed, because the digits are in increasing order, while “1374” is allowed

I know that a four digit password could be anything between 0000 to 9999, hence there are 10,000 combinations. But I am now stuck figuring out how to calculate the number of all possible passwords that are unique, neither increasing nor decreasing.
I have tried to calculate the possible number of passwords if every digit only may be used once:
$$P(n,r)=\frac{10!}{(10−4)!}=\frac{10⋅9⋅8⋅7⋅6⋅5⋅4⋅3⋅2⋅1}{6⋅5⋅4⋅3⋅2⋅1}=5040$$
But I am now quite sure if this is the answer to the question? If not how should I calculate such a question?

Best Answer

As you have already worked out, there are $^{10}P_4=5040$ passwords that repeat no digit.

From this number we are to subtract those passwords whose digits are all increasing or all decreasing. All such passwords can be generated by picking four digits out of the ten without regards to order – there are $\binom{10}4=210$ ways to do so – and then arranging them in increasing or decreasing order as required. Since we have two choices of order, we subtract $210\cdot2=420$ passwords.

Hence there are $5040-420=4620$ passwords with unique digits that are not all increasing or all decreasing.