A370883 Irregular triangle read by rows: T(n,k) is the number of unmatched right parentheses in the k-th string of parentheses of length n, where strings within a row are in reverse lexicographical order.
0, 1, 0, 2, 1, 0, 0, 3, 2, 1, 1, 1, 0, 0, 0, 4, 3, 2, 2, 2, 1, 1, 1, 2, 1, 0, 0, 0, 0, 0, 0, 5, 4, 3, 3, 3, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 6, 5, 4, 4, 4, 3, 3, 3, 4, 3, 2, 2, 2, 2, 2, 2, 4, 3, 2, 2, 2, 1, 1, 1, 2
Offset: 0
Examples
Triangle begins: [0] 0; [1] 1 0; [2] 2 1 0 0; [3] 3 2 1 1 1 0 0 0; [4] 4 3 2 2 2 1 1 1 2 1 0 0 0 0 0 0; ... The strings corresponding to row 2, in reverse lexicographical order, are: "))" (2 unmatched right parentheses), ")(" (1 unmatched right parenthesis), "()" (0 unmatched right parentheses), and "((" (0 unmatched right parentheses). The k-th string in row n corresponds to the binary expansion of k-1, padded with zeros on the left as to make it n digits long, with zeros replaced by ")" and ones replaced by "(". In the following string the position of the unmatched p = 6 right parentheses is denoted by R, the position of the unmatched q-p = 3 left parentheses is denoted by L, and the q+1 = 10 properly nested substrings s_0..s_9 are marked either with E (empty) or * (nonempty). . R R R R R R L L L ) ()() ) (()) ) ) ) ) ( (()) ( (()(()())) ( | \__/ \__/ | | | | \__/ \________/ | E * * E E E E * * E .
References
- Donald E. Knuth, The Art of Computer Programming, Vol. 4A: Combinatorial Algorithms, Part 1, Addison-Wesley, 2011, Section 7.2.1.6, p. 459.
Links
- Paolo Xausa, Table of n, a(n) for n = 0..16382 (rows 0..13 of the triangle, flattened).
Crossrefs
Programs
-
Mathematica
countR[s_] := StringCount[s, "0"] - StringCount[StringJoin[StringCases[s, RegularExpression["1(?R)*+0"]]], "0"]; Array[Map[countR, IntegerString[Range[0, 2^#-1], 2, #]] &, 7, 0]
Comments