A five digit number is written down at random. What is the probability of getting a number that is both divisible by 5 and doesn't have any 2 consecutive digits identical?
I tried to analyse the situation casewise, 1. Last digit is 5 and 2. Last digit is 0, but that did not lead me anywhere because of the added constraint that the first digit can't be 0. I've seen some books where the answer is given as $$\frac{9^3*8*2}{9*10^4}$$ but that isn't the correct answer. There, they have considered that when the last digit is 5, for instance, the third digit is NOT 5. However, the third digit may be 5 in which case, there'll still be 9 options (digits 0 through 9 except 5) to place in the fourth position and so on ...
To crosscheck, I wrote a short code to find out the probability, and it came out to be $$\frac{11809}{9*10^4}$$
Is there any way to find the probability without enumeration ?
Let's say that $a_n$ represents the number of numbers with n digits, which are divisible by 5 and have no 2 consecutive digits identical.
Now, consider the case ($n>2$) where the 2nd digit is nonzero and equal to $p$. Thus, the first digit can anything except $p$ (so as to have non-identical consecutive digits) and $0$ (so that it remains a $n$ digit number). As a result, we have 8 options for the first digit and in each case, the remaining $n-1$ digits is a number of length $n-1$ which also satisfies the required conditions (non-identical and divisible by 5). So, the number of this entire case is possible is in $8\times a_{n-1}$
Next comes the other case, that is where the 2nd digit is $0$. The first digit can be anything but 0 in this case and hence has $9$ options whereas the rest of the number (3rd digit onwards) is a number of length $n-2$ satisfying the required conditions. This entire case is, thus, possible in $9\times a_{n-2}$
Combining these two, we get $$a_n = 8a_{n-1} + 9a_{n-2}$$
Along with $a_1 = 1$ (only 5) and $a_2 = 17$ this linear homogeneous recurrence relation can be solved using Generating Functions or otherwise.
Putting in the ansatz, $a_n = r^n$ we get $$r^n = 8r^{n-1} + 9r^{n-2}$$ which yields on simplifying the characteristic equation $$r^2 -8r -9 = 0$$ which has roots at $-1$ and $9$.
The general solution is $$a_n = \alpha 9^n + \beta (-1)^n$$ Putting in $a_1$ and $a_2$ we arrive at the following formula:
$$a_n = \frac{9^n + 4(-1)^n}{5} $$
For $5$ digit numbers we put $n=5$ to get $$a_5 = \frac{9^5-4}{5} = 11809$$ as required.
The probability is computed by dividing by the total $9\cdot 10^4$ cases.