Suppose we have a set of elements, which we want to rearrange. However, no elements can be moved more than 1 slot away from its original position (items can also be kept in the same position).
For instance, with a 3-element set, $ABC$, there are 3 such arrangements: $ABC$, $BAC$, $ACB$. With a 4 element set, $ABCD$, there are 5 arrangements: $ABCD$, $ABDC$, $ACBD$, $BACD$, $BADC$.
Let $M(n,1)$ be the number of ways to rearrange a set with $n$ elements such that each element can only be moved 1 slot.
Each reordering can either start with $A$... (remaining n-1 elements) or $BA$... (remaining n-2 elements). Hence:
$M(n,1)$ = $M(n-1,1)$ + $M(n-2,1)$
That is, the Fibonacci sequence.
The situation becomes much more complex when we consider $M(n,2)$; that is, each element can be moved up to 2 slots. We can easily calculate the first few terms:
$M(2,2)$ = 2
$M(3,2)$ = 6
$M(4,2)$ = 14
$M(5,2)$ is harder to calculate, but I think it is 32. It is hard to count the number of ways systematically, though. Any ideas of how to go about the problem? Is there any way to find a general formula for $M(n,x)$?
