The playing board for this puzzle is a short list of digits; there is one rule governing possible moves: The 1
may swap with a digit one place to the right; the 2
may swap with a digit two places to the right, and so on.
For example, in the list 1,3,7,2,6,5,4
, you can swap 3
and 6
, because the latter is 3 places to the right of 3
:
┌─┐
┷ ▼
1,3,7,2,6,5,4 → 3,1,7,2,6,5,4
The only other legal moves from this position are to swap 1
and 3
(yielding 3,1,7,2,6,5,4
) or to swap 2
and 5
(yielding 1,6,7,5,3,2,4
):
┌─────┐
┷ ▼
1,3,7,2,6,5,4 → 1,6,7,2,3,5,4
┌───┐
┷ ▼
1,3,7,2,6,5,4 → 1,3,7,5,6,2,4
Here is a graph of all possible states reachable from 1,2,3
:
123 → 213 → 312 → 321
↓ ↑
231 → 132
(For lists of few digits, let's just omit the separating commas).
For the 24 states reachable from 1,2,3,4
, the corresponding graph can be drawn. Do so, and make sure to avoid crossing lines!
Bonus points for symmetries, aesthetics, and for using ASCII-art (or Unicode text ─
│
┌
┐
└
┘
).
If you need to omit the arrowheads, or the labels that distinguish the nodes, that's okay as long as the nodes are recognizable. Maybe mark the 1234
and 4321
nodes.
Is there a cycle (some sequence of two or more moves, after which the board state is the same in the beginning) for any permutation of the numbers 1,2,...,n
, any n
?