MathLabs

Problem 5

Given a permutation (a0,a1,…,an)(a_0, a_1, \ldots, a_n) of the sequence 0,1,…,n0, 1, \ldots, n. A transposition of aia_i with aja_j is called legal if ai=0a_i = 0 for i>0i > 0, and ai−1+1=aja_{i-1} + 1 = a_j. The permutation (a0,a1,…,an)(a_0, a_1, \ldots, a_n) is called regular if after a number of legal transpositions it becomes (1,2,…,n,0)(1, 2, \ldots, n, 0). For which numbers nn is the permutation (1,n,n−1,…,3,2,0)(1, n, n-1, \ldots, 3, 2, 0) regular?
Step 3 of 5: Define the block configuration PrP_r and reach P1P_1 for odd nn
In plain words

When nn is odd, the first leftward sweep jumps all the way to a1=na_1 = n, pairing every even number with the odd number above it into sorted blocks of length 22.

Pr=[1:R−1],(0),[N−R:N−1],[N−2R:N−R−1],…,[2R:3R−1],[R:2R−1](R=2r, N=n+1)P_r = [1 : R-1], (0), [N-R : N-1], [N-2R : N-R-1], \ldots, [2R : 3R-1], [R : 2R-1] \quad (R = 2^r,\ N = n+1)
Detailed analysis

For odd n≥3n \ge 3, set N=n+1N = n + 1 and R=2rR = 2^r, and write [a:b]=(a,a+1,…,b)[a : b] = (a, a+1, \ldots, b) for a contiguous ascending block. Let P0P_0 be the initial permutation and define PrP_r as [1:R−1],(0),[N−R:N−1],[N−2R:N−R−1],…,[2R:3R−1],[R:2R−1][1 : R-1], (0), [N-R : N-1], [N-2R : N-R-1], \ldots, [2R : 3R-1], [R : 2R-1] whenever 2R∣N2R \mid N. In the first pass from P0P_0, since nn is odd, 00 swaps successively with 3,5,…,n3, 5, \ldots, n, landing at index 11 right after 11 and pairing the remaining entries into [N−2:N−1],[N−4:N−3],…,[2:3][N-2 : N-1], [N-4 : N-3], \ldots, [2 : 3], which is exactly P1P_1.