login
Triangle of permutations of [1..n] made by alternatively reversing terms counted from the left and right. (See comment.)
3

%I #38 Apr 19 2023 21:52:28

%S 1,2,1,2,3,1,3,1,2,4,2,1,5,4,3,1,3,2,5,6,4,6,1,2,3,5,4,7,1,7,4,5,6,8,

%T 3,2,9,7,6,1,4,5,3,2,8,7,10,8,3,6,9,5,4,1,2,5,11,10,7,6,3,8,9,1,2,4,

%U 11,10,12,1,4,5,9,6,3,2,7,8,3,6,7,11,10,5,4,9,12,13,1,8,2,14,6,7,1,2,3,13,10,9,4,5,8,11,12

%N Triangle of permutations of [1..n] made by alternatively reversing terms counted from the left and right. (See comment.)

%C Start with [1..n]. Reverse the order of the leftmost 1 element. (trivial) Reverse the order of the rightmost 2 elements. Reverse the order of the leftmost 3 elements of the previous permutation. Reverse the order of the rightmost 4 elements of the previous permutation. ...until... Reverse the order of the rightmost n elements of the (n-1)th permutation if n is even. Or reverse the order of the leftmost n elements of the (n-1)th permutation if n is odd. (Of course, these options are the same thing, reversing the order of the entire permutation.)

%H John Tyler Rascoe, <a href="/A097825/b097825.txt">Rows n = 1..148 of triangle, flattened</a>

%e For n=6, the reversals steps are:

%e [1,2,3,4,5,6]->[1,2,3,4,5,6]->[1,2,3,4,6,5]->[3,2,1,4,6,5]->[3,2,5,6,4,1]->[4,6,5,2,3,1]->[1,3,2,5,6,4].

%e Triangle begins:

%e k=1 2 3 4 5 6

%e n=1: 1,

%e n=2: 2, 1,

%e n=3: 2, 3, 1,

%e n=4: 3, 1, 2, 4,

%e n=5: 2, 1, 5, 4, 3,

%e n=6: 1, 3, 2, 5, 6, 4,

%e ...

%p p:=proc(n) local B,k,u,rev,w; with(linalg): u:=n->[seq(i,i=1..n)]; rev:=proc(a) [seq(a[nops(a)+1-i],i=1..nops(a))] end; w:=(m,n)->[seq(i,i=m..n)]; B[0]:=matrix(1,n,u(n)): if n mod 2 = 0 then for k from 1 to n/2 do B[2*k-1]:=concat(submatrix(B[2*k-2],[1],rev(u(2*k-1))),submatrix(B[2*k-2],[1],w(2*k,n))): B[2*k]:=concat(submatrix(B[2*k-1],[1],u(n-2*k)),submatrix(B[2*k-1],[1],rev(w(n+1-2*k,n)))) od else for k from 1 to (n-1)/2 do B[2*k-1]:=concat(submatrix(B[2*k-2],[1],rev(u(2*k-1))),submatrix(B[2*k-2],[1],w(2*k,n))): B[2*k]:=concat(submatrix(B[2*k-1],[1],u(n-2*k)),submatrix(B[2*k-1],[1],rev(w(n+1-2*k,n)))) od: B[n]:=concat(submatrix(B[n-1],[1],rev(u(n))),submatrix(B[n-1],[1],[])) fi end: for n from 1 to 12 do p(n) od; # supplies the sequence in triangular form # _Emeric Deutsch_, Nov 17 2004

%o (Python)

%o def A097825_row(n):

%o c = list(range(1,n+1))

%o for j in range(2,n):

%o if j%2 == 0: c = c[:n-j]+c[:n-j-1:-1]

%o else: c = c[j-1::-1]+c[j:]

%o return(c[::-1])

%o for n in range(1,15):

%o print(n,A097825_row(n)) # _John Tyler Rascoe_, Apr 14 2023

%Y Cf. A097510 (column k=1), A097511 (main diagonal).

%K easy,nonn,tabl

%O 1,2

%A _Leroy Quet_, Aug 26 2004

%E More terms from _Emeric Deutsch_, Nov 17 2004

%E Name edited by _John Tyler Rascoe_, Apr 19 2023