# Number of 5 digit numbers $< 40,000$

The numbers to be used are : 2, 3, 4, 4, 5

The way I approached this is:

Total number of combinations possible is :

$$\frac{5!}{2!}$$

Total number of combinations starting with 4 :

$$4!$$

Total number of combinations starting with 5 :

$$\frac{4!}{2!}$$

$\therefore$ the total number of numbers $<$ 40,000 :

$$\frac{5!}{2!}-\Big(4!+\frac{4!}{2!}\Big)$$

I came across with this question and I don't have access to the solution.

I'm not confident if this is correct.

• You must use the digits $2,3,4,4,5$ ? – user252450 Dec 17 '15 at 7:56
• The solution is correct .Try to look at it again and understand why it's correct . – user252450 Dec 17 '15 at 8:01
• @ComplexPhi Yes we must use those digits only – Siddharth Thevaril Dec 17 '15 at 8:04

## 2 Answers

You have to use digits $2,3,4,4,5$, and it can't exceed $40000$. That means, you can't start your number with $4$ or $5$. That leaves you with the option to start with $2$ or $3$. If you started your number, you still have $4$ digits, but $2$ of them are the same, so the total possibilities are $\frac{4!}{2!}$, and you multiply this with $2$, since you can start with either $2$ or $3$, therefore the answer is $24$. Your solution is correct, but I just wanted to show you a "clearer" one.

To double-check the answer, you can use brute force:

\$ python
>>> sum(sorted(str(x)) == sorted(str(23445)) for x in range(40000))
24

• Really nice code, +1 :) – Atvin Dec 17 '15 at 8:38
• Alternatively, Here is Mathematica code (it's quicker in theory, since it checks only 60 permutations and not 40000 numbers): Count[Map[Total[10^(Range - 1)*#] &, Permutations[{2, 3, 4, 4, 5}]], x_ /; x < 40000] – Meni Rosenfeld Dec 17 '15 at 10:34