# Counting number of 4 digit numbers having 3 distinct digits in octal number system

There was an answer given to this question at https://math.stackexchange.com/a/4252652/967301, in which I am facing difficulty to understand :

There are 2 parts in here to the solution :-

Firstly when we are counting all the cases including 0's, which according to me should be 8c1 * 7c1 * 6c1 * 3c1 * (4!/2!1) , I can't figure it out why is it wrong , (what I did is that first digit can be picked in 8 ways , second in 7 ways, third digit in 6 ways and the fourth digit will be a repetition of the previous 3 , therefore it can be selected in 3c1 ways) , and finally we will arrange such number by multiplying it with 4!/2! (2! as it contains 2 digits of same kind)

Secondly , I am not able to think of how we are using the concept of probability in here, how are we sure that there will be exactly 1/8 of all such possible 4 digit numbers in which we would have 0 as leading digit

• As far as the 2nd question goes, easier to stretch your intuition by considering base $10$ numbers. Suppose that you are considering the numbers $0,1,\cdots,9999$ and further suppose that all such numbers are zero filled on the left, so that you have $10,000$ 4 digit numbers. Let $S$ denote the subset of these $10,000$ numbers which have their leftmost digit $= 0$. Let $|S|$ denote the number of elements in the set $S$. [1] Identify the set $S$ : precisely which numbers does it contain? [2] What is $\frac{|S|}{10000}$? Sep 27, 2021 at 15:14
• As more food for thought, re previous comment, let $T$ denote the subset of these 10,000 numbers which have their rightmost digit $= 0.$ Let $|T|$ denote the number of elements in $T$. Note that $n \in T ~\iff ~10 ~| ~n$. [1] Identify the set $T$ : precisely which numbers does it contain. [2] What is $\frac{|T|}{10000}$? [3] Consider the relationship between $|S|$ and $|T|$. Is this relationship a coincidence? Sep 27, 2021 at 15:19
• As still more food for thought, consider a related question. Let $U$ denote the subset of the $10,000$ numbers that have a $0$ in the second digit from the left. In trying to compute $|U|$, note that you can form a bijection between $U$ and $S$ where each number in $U$ is transformed into a number in $S$, by altering an element $n$ from $U$ as follows: Truncate the leftmost digit from $n$, and then reposition this removed digit so that it becomes the rightmost digit. If you have a bijection between two finite sets, what can you say about the number of elements in each set? Sep 27, 2021 at 15:29

The answer in question subtracts the number of four-digit octal strings having exactly three distinct digits that have a zero in the first position from the total number of four-digit octal strings having exactly three distinct digits.

In counting the total number of four-digit octal strings having exactly three digits, you made the mistake of imposing an order on your selections. Selecting the digits $$6, 7, 8$$ in that order and then selecting $$8$$ to be the repeated digit has the same effect as selecting the digits $$8, 7, 6$$ in that order and then selecting $$8$$ to be the repeated digit. Since there are $$3!$$ ways of arranging the three distinct digits you selected, you counted each admissible octal string $$3! = 6$$ times.

Number of four-digit octal strings with exactly three distinct digits: Choose which three of the eight octal digits will appear in the number, which can be done in $$\binom{8}{3}$$ ways. Choose which of the three selected digits will appear twice. Arrange the selected digits, which can be done in $$\binom{4}{2, 1, 1}$$ ways. This yields $$\binom{8}{3} \cdot 3 \cdot \binom{4}{2, 1, 1} = \frac{8!}{3!5!} \cdot 3 \cdot \frac{4!}{2!1!1!} = 2016$$ four-digit octal strings having exactly three distinct digits.

There are eight possible digits which could occupy the first digit of the octal string, of which one is $$0$$. Hence, the probability that the first digit is $$0$$ is $$1/8$$.

The symmetry may not be clear since one of the digits must appear twice, so let's verify the above assertion by counting the number of four-digit octal strings with a zero in the first position that have exactly three distinct digits.

Number of four-digit octal strings with a zero in the first position that have exactly three distinct digits: We will consider two cases, depending on whether zero is the repeated digit.

Zero is the repeated digit: There are three ways to place the second zero, seven ways to fill the first open position with an octal digit other than zero, and six ways to fill the remaining open position with one of the remaining six octal digits. Hence, there are $$3 \cdot 7 \cdot 6 = 126$$ such octal strings.

Zero is not the repeated digit: There are seven ways to select which of the remaining octal digits will appear twice, $$\binom{3}{2}$$ ways to select which two of the remaining three positions that digit will occupy, and six ways to select which of the remaining six octal digits will fill the remaining open position. Hence, there are $$7 \cdot \binom{3}{2} \cdot 6 = 126$$ such octal strings.

Total: Since these two cases are mutually exclusive and exhaustive, there are $$3 \cdot 7 \cdot 6 + 7 \cdot \binom{3}{2} \cdot 6 = 126 + 126 = 252$$ four-digit octal strings with a zero in the first position that have exactly three distinct digits.

Hence, the probability that a four-digit octal string with exactly three distinct digits has a zero in the first position is $$\frac{252}{2016} = \frac{1}{8}$$ as claimed above.