How many $N$ digit numbers are there such that neighboring digits are distinct and first and last digits are distinct too.
For $2$ digits there are $9\cdot 9$ obviously.
For $3$ digits it's $9\cdot 8\cdot 8+9\cdot 1\cdot 9$.
Same logic I can apply for $4$ and $5$ digits but the number of terms grows and it becomes hard to keep track. So how to proceed?
First let's not exclude that the first digit takes value $0$.
(Excluding afterwards that the first digit takes value $0$ means that the outcome must be mupltiplied with $0.9$)
Let $A=\{0,1,2,3,4,5,6,7,8,9\}^N$
For $i=1,\dots,N-1$ let $A_i=\{d\in A\mid d_i=d_{i+1}\}$
Let $A_N=\{d\in A\mid d_N=d_1\}$.
To be found is then $|A-A_1\cup\dots\cup A_N|=10^N-|A_1\cup\dots\cup A_N|$
Here $|A_1\cup\cdots\cup A_N|$ can be found by inclusion/exclusion applying that $|A_{i_1}\cap\cdots\cap A_{i_k}|=10^{N-k}$ whenever $1\leq i_1<i_2<\cdots<i_k\leq N$ and $k<N$ together with $|A_1\cap\dots\cap A_N|=10$.
This leads to:$$\sum_{i=0}^{N-1}\binom{N}i(-1)^i10^{N-i}+(-1)^N10=\sum_{i=0}^{N}\binom{N}i(-1)^i10^{N-i}-(-1)^N+(-1)^N10=$$$$9^N+9(-1)^N$$
So the final outcome ($0$ excluded as first digid) is:$$\frac9{10}\left(9^N+9(-1)^N\right)$$