[Math] Find the number of seven digit whole numbers in which only 2 and 3 are present as digits if no two 2’s are consecutive in any number

algebra-precalculusnumber theorypermutations

Find the number of seven digit whole numbers in which only $2$ and $3$ are present as digits if no two $2$'s are consecutive in any number?

My Approach:
We can make numbers and see like: $2323232$, $2333333$, $2332332$, etc. Please suggest alternate solution of this will be of great help thanks.

Best Answer

Say $K(n)$ is the number of such n-digit numbers. Then if 2 is the first digit, the second digit must be 3, and after those two digits there are $n-2$ more digits obeying the same rule, so there are $K(n-2)$ such $n$-digit numbers beginning with $23$. There are $K(n-1)$ such numbers beginning with 3. Thus we get the recursion

$$K(n)=K(n-1)+K(n-2)$$

where $K(1)=2$ and $K(2)=3$. Note the relation to the Fibonacci sequence $F(n)$. We have $K(n)=F(n+1)$, and $K(7)=F(8)=21$.