I am trying to solve a problem: We are asked to find the number of $9-$digit numbers by using the digits from $1$ to $9$ only once. There is also one more restriction. Consecutive digits should not be positioned side by side.
For example, $814953627$ is convenient while $8\mathbf{21}574936$ is not.
It seems a hard problem to me. $1$ and $9$ have one consecutive digit while others have two. This makes the problem harder a bit. So I tried to establish a recurrence relation. For $2\leq n\leq 9$, if the number of such numbers is $A_n$, we can use $A_{n-1}$. For each such $(n-1)-$digit numbers, we can find $n-2$ such $n-$digit numbers. Let me give an example, if $n=5$, and we have such a $4-$digit number, $3142$ for instance, we have three position to place digit $5$. Therefore $$A_n = (n-2)A_{n-1} + \cdots$$ Of course this is not the only way to have such an $n-$digit number. We also place the digit $n$ between two consecutive digits. Again if we take $n=5$, and if we have an inconvenient $4-$digit number $4231$, we can place the digit $5$ between $2$ and $3$, and we obtain a convenient $5-$digit number $42531$. However, in this case, we must have only two digits positioned side by side and one of them must not be $n-1$. So, if we say $B_n$ the number of $n-$digit numbers whose digits vary between $1$ and $n$ and it has two and only two consecutive digits in consecutive positions such that consectuive digits are different than $n$, then we have $$A_n = (n-2)A_{n-1} + B_{n-1}.$$ However, we need to have one more recurrence ralation in order to find $B_{n-1}$. I could not find yet. What should I do? Trying to solve by using a completely different method or going over $B_n$? Your helps make me happy for both cases.