login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

Irregular triangle T(n,k) read by rows: row n lists the positions of right parentheses in the properly nested string of parentheses encoded by A063171(n).
3

%I #21 Mar 27 2024 16:32:28

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

%T 7,8,2,6,7,8,3,4,6,8,3,4,7,8,3,5,6,8,3,5,7,8,3,6,7,8,4,5,6,8,4,5,7,8,

%U 4,6,7,8,5,6,7,8,2,4,6,8,10,2,4,6,9,10,2,4,7,8,10

%N Irregular triangle T(n,k) read by rows: row n lists the positions of right parentheses in the properly nested string of parentheses encoded by A063171(n).

%C See A370220 for the positions of left parentheses.

%D Donald E. Knuth, The Art of Computer Programming, Vol. 4A: Combinatorial Algorithms, Part 1, Addison-Wesley, 2011, Section 7.2.1.6, pp. 440-444.

%H Paolo Xausa, <a href="/A371409/b371409.txt">Table of n, a(n) for n = 1..15521</a> (rows 1..2055 of the triangle, flattened).

%e The following table lists the positions of right parentheses for properly nested strings having lengths up to 8, along with the positions of left parentheses.

%e .

%e | Properly | | Pos. of right | Pos. of left

%e | Nested | A063171 | parentheses | parentheses

%e n | String | (n) | (this seq.) | (A370220)

%e ----+----------+----------+---------------+---------------

%e 1 | () | 10 | 2 | 1

%e 2 | ()() | 1010 | 2 4 | 1 3

%e 3 | (()) | 1100 | 3 4 | 1 2

%e 4 | ()()() | 101010 | 2 4 6 | 1 3 5

%e 5 | ()(()) | 101100 | 2 5 6 | 1 3 4

%e 6 | (())() | 110010 | 3 4 6 | 1 2 5

%e 7 | (()()) | 110100 | 3 5 6 | 1 2 4

%e 8 | ((())) | 111000 | 4 5 6 | 1 2 3

%e 9 | ()()()() | 10101010 | 2 4 6 8 | 1 3 5 7

%e 10 | ()()(()) | 10101100 | 2 4 7 8 | 1 3 5 6

%e 11 | ()(())() | 10110010 | 2 5 6 8 | 1 3 4 7

%e 12 | ()(()()) | 10110100 | 2 5 7 8 | 1 3 4 6

%e 13 | ()((())) | 10111000 | 2 6 7 8 | 1 3 4 5

%e 14 | (())()() | 11001010 | 3 4 6 8 | 1 2 5 7

%e 15 | (())(()) | 11001100 | 3 4 7 8 | 1 2 5 6

%e 16 | (()())() | 11010010 | 3 5 6 8 | 1 2 4 7

%e 17 | (()()()) | 11010100 | 3 5 7 8 | 1 2 4 6

%e 18 | (()(())) | 11011000 | 3 6 7 8 | 1 2 4 5

%e 19 | ((()))() | 11100010 | 4 5 6 8 | 1 2 3 7

%e 20 | ((())()) | 11100100 | 4 5 7 8 | 1 2 3 6

%e 21 | ((()())) | 11101000 | 4 6 7 8 | 1 2 3 5

%e 22 | (((()))) | 11110000 | 5 6 7 8 | 1 2 3 4

%t zlist[m_] := With[{r = 2*Range[2, m]}, Reverse[Map[Join[{1}, #] &, Select[Subsets[Range[2, 2*m-1], {m-1}], Min[r-#] > 0 &]]]];

%t Table[Delete[Map[Complement[Range[2*m], #] &, zlist[m]], 0], {m, 5}] (* _Paolo Xausa_, Mar 27 2024 *)

%t (* 2nd program: uses Algorithm Z from Knuth's TAOCP section 7.2.1.6, exercise 2 *)

%t zlist[m_] := Block[{z = 2*Range[m] - 1, j},

%t Reap[

%t While[True,

%t Sow[z];

%t If[z[[m-1]] < z[[m]] - 1,

%t z[[m]]--,

%t j = m - 1; z[[m]] = 2*m - 1;

%t While[j > 1 && z[[j-1]] == z[[j]] - 1, z[[j]] = 2*j - 1; j--];

%t If[j == 1,Break[]];

%t z[[j]]--]

%t ]][[2]][[1]]];

%t Join[{{2}}, Table[Delete[Map[Complement[Range[2*m], #] &, zlist[m]], 0], {m, 2, 5}]] (* _Paolo Xausa_, Mar 27 2024 *)

%Y Cf. A063171, A370220, A072643 (row lengths), A371410 (row sums).

%K nonn,tabf

%O 1,1

%A _Paolo Xausa_, Mar 22 2024