TITLE: permutation and f(n) challenge
QUESTION [6 upvotes]: Suppose $f(n)$ be the number of permutation from set ${1,2,..,n}$ such
that for each $ 1 \leq i \leq n$ we have: $ | \pi(i)-i| \leq 1 $.
meaning of $ \pi(i)$ is an elements whose in place $i$ of permutation.
for example in permutation $<2,3,1>$, $ \pi(1)=2$.


how we reach to $f(10)= 89$

REPLY [6 votes]: How did you get $f(10)=4$? For $f(2n)$, there are at least $2^n$ permutations, since you can swap every pair of neighbors in $123\cdots n$. 
This is induction. For $n=1$, $f(1)=1$, $f(2)=2$. Notice that $f(n+1)=f(n)+f(n-1)$, accounting for: if $\pi(n+1)=n+1$, there are $f(n)$ many permutations, if $\pi(n+1)=n$, then $\pi(n)=n+1$, and there are $f(n-2)$ such permutations. There are no other options since the index of $n+1$ cannot be less than $n$. 
This is the Fibonacci recurrence, so $f(n)=F_{n+1}$, where $F_n$ is the $n$'th Fibonacci number. Then as you point out, $f(10)=89$.