cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-10 of 13 results. Next

A071158 Factorial expansion of A071156.

Original entry on oeis.org

1, 11, 21, 111, 121, 211, 221, 321, 1111, 1121, 1211, 1221, 1321, 2111, 2121, 2211, 2221, 2321, 3211, 3221, 3321, 4321, 11111, 11121, 11211, 11221, 11321, 12111, 12121, 12211, 12221, 12321, 13211, 13221, 13321, 14321, 21111, 21121, 21211
Offset: 1

Views

Author

Antti Karttunen, May 14 2002

Keywords

Comments

Note that this decimal representation works only as long as there does not appear any digit 'ten' or higher in the factorial expansion of A071156.

Crossrefs

a(n) = A007623(A071156(n)) = A071157(A057164(n)).

A085198 Function whose restriction to A014486 gives A071156.

Original entry on oeis.org

0, 0, 1, 0, 5, 0, 1, 0, 23, 2, 3, -1, 5, 0, 1, 0, 119, 14, 15, -1, 17, 0, 1, -2, 23, 2, 3, -1, 5, 0, 1, 0, 719, 86, 87, 5, 89, 6, 7, -4, 95, 8, 9, -3, 11, -2, -1, -3, 119, 14, 15, -1, 17, 0, 1, -2, 23, 2, 3, -1, 5, 0, 1, 0, 5039, 566, 567, 53, 569, 54, 55, -4, 575, 56, 57, -3, 59, -2, -1, -7, 599, 62, 63, -1, 65, 0, 1, -6, 71, 2, 3, -5, 5, -4, -3
Offset: 0

Views

Author

Antti Karttunen, Jun 14 2003

Keywords

Crossrefs

A071156(n) = a(A014486(n)).

A085191 First differences of A071156.

Original entry on oeis.org

1, 2, 2, 4, 2, 4, 2, 6, 10, 2, 4, 2, 6, 10, 2, 4, 2, 6, 16, 2, 6, 24, 34, 2, 4, 2, 6, 10, 2, 4, 2, 6, 16, 2, 6, 24, 34, 2, 4, 2, 6, 10, 2, 4, 2, 6, 16, 2, 6, 24, 58, 2, 4, 2, 6, 16, 2, 6, 24, 88, 2, 6, 24, 120, 154, 2, 4, 2, 6, 10, 2, 4, 2, 6, 16, 2, 6, 24, 34, 2, 4, 2, 6, 10, 2, 4, 2, 6, 16, 2, 6
Offset: 0

Views

Author

Antti Karttunen, Jun 14 2003

Keywords

Crossrefs

Repeating part: A085190.

Formula

a(n) = A071156(n+1) - A071156(n).

A126311 A071156-codes for the fixed points of the permutation A125985/A125986.

Original entry on oeis.org

0, 1, 327, 13383, 14107138025, 4217868316383
Offset: 0

Views

Author

Antti Karttunen, Jan 02 2007

Keywords

Comments

A126301 shows the same terms in factorial base notation.

Crossrefs

Formula

a(n) = A071156(A126300(n))

A085199 Inverse function of N -> N injection A071156.

Original entry on oeis.org

0, 1, 0, 2, 0, 3, 0, 0, 0, 4, 0, 5, 0, 0, 0, 6, 0, 7, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 10, 0, 0, 0, 11, 0, 12, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 15, 0, 0, 0, 16, 0, 17, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 20, 0, 0, 0, 0, 0, 21, 0, 0, 0
Offset: 0

Views

Author

Antti Karttunen, Jun 14 2003

Keywords

Comments

a(0)=0 because A071156(0)=0, but a(n) = 0 also for those n which do not occur as values of A071156. All positive natural numbers occur here once.

Crossrefs

a(A071156(n)) = n for all n.

Formula

a(n) = A057164(A085200(n)).

A014486 List of totally balanced sequences of 2n binary digits written in base 10. Binary expansion of each term contains n 0's and n 1's and reading from left to right (the most significant to the least significant bit), the number of 0's never exceeds the number of 1's.

Original entry on oeis.org

0, 2, 10, 12, 42, 44, 50, 52, 56, 170, 172, 178, 180, 184, 202, 204, 210, 212, 216, 226, 228, 232, 240, 682, 684, 690, 692, 696, 714, 716, 722, 724, 728, 738, 740, 744, 752, 810, 812, 818, 820, 824, 842, 844, 850, 852, 856, 866, 868, 872, 880, 906, 908, 914
Offset: 0

Views

Author

Keywords

Comments

The binary Dyck-Language (A063171) in decimal representation.
These encode width 2n mountain ranges, rooted planar trees of n+1 vertices and n edges, planar planted trees with n nodes, rooted plane binary trees with n+1 leaves (2n edges, 2n+1 vertices, n internal nodes, the root included), Dyck words, binary bracketings, parenthesizations, non-crossing handshakes and partitions and many other combinatorial structures in Catalan family, enumerated by A000108.
Is Sum_{k=1..n} a(k) / n^(5/2) bounded? - Benoit Cloitre, Aug 18 2002
This list is the intersection of A061854 and A031443. - Jason Kimberley, Jan 18 2013
The sequence does start at n = 0, since in the binary interpretation of the Dyck language (e.g., as parenthesizations where "1" stands for "(" and "0" stands for ")") having a(0) = 0 will do since it would stand for the empty string where the "0"s and "1"s are balanced (hence the parentheses are balanced). - Daniel Forgues, Feb 17 2013
It appears that for n>=1 this sequence can be obtained by concatenating the terms of the irregular array whose n-th row length is A000108(n) and that is defined recursively by B(n,0) = A020988(n) and B(n,k) = B(n, k-1) + D(n, k-1) where D(x,y) = (2^(2*(A089309(B(x,y))-1))-1)*(2/3) + 2^A007814(B(x,y)). - Raúl Mario Torres Silva and Michel Marcus, May 01 2020
This encoding is related to the ranking by standard ordered tree numbers in that (1) the binary encoding of trees ordered by standard ranking is given by A358505, while (2) the standard ranking of trees ordered by binary encoding is given by A358523. - Gus Wiseman, Nov 21 2022

Examples

			a(19) = 226_10 = 11100010_2 = A063171(19) as bracket expression: ( ( ( ) ) )( ) and as a binary tree, proceeding from left to right in depth-first fashion, with 1's in binary expansion standing for internal (branching) nodes and 0's for leaves:
  0   0
   \ /
    1   0 0  (0)
     \ /   \ /
      1     1
       \   /
         1
Note that in this coding scheme the last leaf of the binary trees (here in parentheses) is implicit. This tree can be also converted to a particular S-expression in languages like Lisp, Scheme and Prolog, if we interpret its internal nodes (1's) as cons cells with each leftward leaning branch being the "car" and the rightward leaning branch the "cdr" part of the pair, with the terminal nodes (0's) being ()'s (NILs). Thus we have (cons (cons (cons () ()) ()) (cons () ())) = '( ( ( () . () ) . () ) . ( () . () ) ) = (((())) ()) i.e., the same bracket expression as above, but surrounded by extra parentheses. This mapping is performed by the Scheme function A014486->parenthesization given below.
From _Gus Wiseman_, Nov 21 2022: (Start)
The terms and corresponding ordered rooted trees begin:
    0: o
    2: (o)
   10: (oo)
   12: ((o))
   42: (ooo)
   44: (o(o))
   50: ((o)o)
   52: ((oo))
   56: (((o)))
  170: (oooo)
  172: (oo(o))
  178: (o(o)o)
  180: (o(oo))
  184: (o((o)))
(End)
		

References

  • Donald E. Knuth, The Art of Computer Programming, Vol. 4A: Combinatorial Algorithms, Part 1, Addison-Wesley, 2011, Section 7.2.1.6, pp. 443 (Algorithm P).

Crossrefs

Characteristic function: A080116. Inverse function: A080300.
The terms of binary width 2n are counted by A000108(n). Subset of A036990. Number of peaks in each mountain (number of leaves in rooted plane general trees): A057514. Number of trailing zeros in the binary expansion: A080237. First differences: A085192.
Branches of the ordered tree are counted by A057515.
Edges of the ordered tree are counted by A072643.
The Matula-Goebel number of the ordered tree is A127301.
The standard ranking of the ordered tree is A358523.
The depth of the ordered tree is A358550.
Nodes of the ordered tree are counted by A358551.

Programs

  • Maple
    # Maple procedure CatalanUnrank is adapted from the algorithm 3.24 of the CAGES book and the Scheme function CatalanUnrank from Ruskey's thesis. See the a089408.c program for the corresponding C procedures.
    CatalanSequences := proc(upto_n) local n,a,r; a := []; for n from 0 to upto_n do for r from 0 to (binomial(2*n,n)/(n+1))-1 do a := [op(a),CatalanUnrank(n,r)]; od; od; return a; end;
    CatalanUnrank := proc(n,rr) local r,x,y,lo,m,a; r := (binomial(2*n,n)/(n+1))-(rr+1); y := 0; lo := 0; a := 0; for x from 1 to 2*n do m := Mn(n,x,y+1); if(r <= lo+m-1) then y := y+1; a := 2*a + 1; else lo := lo+m; y := y-1; a := 2*a; fi; od; return a; end;
    Mn := (n,x,y) -> binomial(2*n-x,n-((x+y)/2)) - binomial(2*n-x,n-1-((x+y)/2));
    # Alternative:
    bin := n -> ListTools:-Reverse(convert(n, base, 2)):
    isA014486 := proc(n): local B, s, b; s := 0;
        if n > 0 then
          for b in bin(n) do
              s := s + ifelse(b = 1, 1, -1);
               if 0 > s then return false fi;
          od fi;
      s = 0 end:
    select(isA014486, [seq(0..240)]);  # Peter Luschny, Mar 13 2024
  • Mathematica
    cat[ n_ ] := (2 n)!/n!/(n+1)!; b2d[li_List] := Fold[2#1+#2&, 0, li]
    d2b[n_Integer] := IntegerDigits[n, 2]
    tree[n_] := Join[Table[1, {i, 1, n}], Table[0, {i, 1, n}]]
    nexttree[t_] := Flatten[Reverse[t]/. {a___, 0, 0, 1, b___}:> Reverse[{Sort[{a, 0}]//Reverse, 1, 0, b}]]
    wood[ n_ /; n<8 ] := NestList[ nexttree, tree[ n ], cat[ n ]-1 ]
    Table[ Reverse[ b2d/@wood[ j ] ], {j, 0, 6} ]//Flatten
    (* Alternative code *)
    tbQ[n_]:=Module[{idn2=IntegerDigits[n,2]},Count[idn2,1]==Length[idn2]/2&&Min[Accumulate[idn2/.{0->-1}]]>=0]; Join[{0},Select[Range[900],tbQ]] (* Harvey P. Dale, Jul 04 2013 *)
    balancedQ[0] = True; balancedQ[n_] := Module[{s = 0}, Do[s += If[b == 1, 1, -1]; If[s < 0, Return[False]], {b, IntegerDigits[n, 2]}]; Return[s == 0] ]; A014486 = FromDigits /@ IntegerDigits[Select[Range[0, 1000], balancedQ ]] (* Jean-François Alcover, Mar 05 2016 *)
    A014486Q[0] = True; A014486Q[n_] := Catch[Fold[If[# < 0, Throw[False], If[#2 == 0, # - 1, # + 1]] &, 0, IntegerDigits[n, 2]] == 0]; Select[Range[0, 880], A014486Q] (* JungHwan Min, Dec 11 2016 *)
    (* Uses Algorithm P from Knuth's TAOCP section 7.2.1.6 - see References and Links. *)
    alist[n_] := Block[{a = Flatten[Table[{1, 0}, n]], m = 2*n - 1, j, k},
        FromDigits[#, 2]& /@ Reap[
        While[True,
            Sow[a]; a[[m]] = 0;
            If[a[[m - 1]] == 0,
                a[[--m]] = 1, j = m - 1; k = 2*n - 1;
                While[j > 1 && a[[j]] == 1, a[[j--]] = 0; a[[k]] = 1; k -= 2];
                If[j == 1, Break[]];
                a[[j]] = 1; m = 2*n - 1]
        ]][[2, 1]]];
    Join[{{0}, {2}}, Array[alist, 4, 2]] (* Paolo Xausa, Mar 16 2024 *)
  • PARI
    isA014486(n)=my(v=binary(n),t=0);for(i=1,#v,t+=if(v[i],1,-1);if(t<0,return(0))); t==0 \\ Charles R Greathouse IV, Jun 10 2011
    
  • PARI
    a_rows(N) = my(a=Vec([[0]], N)); for(r=1, N-1, my(b=a[r], c=List()); foreach(b, t, my(v=if(t, valuation(t, 2), 0)); for(i=0, v, listput(~c, (t<<2)+(2<Ruud H.G. van Tol, May 16 2024
    
  • Python
    from itertools import count, islice
    from sympy.utilities.iterables import multiset_permutations
    def A014486_gen(): # generator of terms
        yield 0
        for l in count(1):
            for s in multiset_permutations('0'*l+'1'*(l-1)):
                c, m = 0, (l<<1)-1
                for i in range(m):
                    if s[i] == '1':
                        c += 2
                    if cA014486_list = list(islice(A014486_gen(),30)) # Chai Wah Wu, Nov 28 2023
  • SageMath
    def is_A014486(n) :
        B = bin(n)[2::] if n != 0 else 0
        s = 0
        for b in B :
            s += 1 if b=='1' else -1
            if 0 > s : return False
        return 0 == s
    def A014486_list(n): return [k for k in (1..n) if is_A014486(k) ]
    A014486_list(888) # Peter Luschny, Aug 10 2012
    

Extensions

Additional comments from Antti Karttunen, Aug 11 2000 and May 25 2004
Added a(0)=0 (which had been removed in June 2011), Joerg Arndt, Feb 27 2013

A227157 Numbers k whose factorial base representation A007623(k) does not contain any nonleading zeros.

Original entry on oeis.org

1, 3, 5, 9, 11, 15, 17, 21, 23, 33, 35, 39, 41, 45, 47, 57, 59, 63, 65, 69, 71, 81, 83, 87, 89, 93, 95, 105, 107, 111, 113, 117, 119, 153, 155, 159, 161, 165, 167, 177, 179, 183, 185, 189, 191, 201, 203, 207, 209, 213, 215, 225, 227, 231, 233, 237, 239, 273
Offset: 1

Views

Author

Antti Karttunen, Jul 04 2013

Keywords

Comments

a(A003422(n)) = A007489(n).
a(A007489(n)) = (n+1)!-1 thus A007489(n) gives the number of terms less than (n+1)! in this sequence.
Equivalently, there are n! terms in the sequence with their magnitude in range n!..(n+1)!.
Also numbers k such that A304036(k) = 1 for k > 0. - Seiichi Manyama, May 06 2018

Crossrefs

The sequence gives all n for which A208575(n) is not zero. Complement of A227187. Subsets: A071156 (apart from zero), A231716, A231720.

Programs

  • Mathematica
    q[n_] := Module[{k = n, m = 2, c = 0, r}, While[{k, r} = QuotientRemainder[k, m]; k != 0 || r != 0, If[r == 0, c++]; m++]; c == 0]; Select[Range[300], q] (* Amiram Eldar, Jan 23 2024 *)

A239903 List of Restricted-Growth Strings a_{k-1}a_{k-2}...a_{2}a_{1}, with k=2 and a_1 in {0,1} or k>2, a_{k-1}=1 and a_{j+1}>=1+a_j, for k-1>j>0.

Original entry on oeis.org

0, 1, 10, 11, 12, 100, 101, 110, 111, 112, 120, 121, 122, 123, 1000, 1001, 1010, 1011, 1012, 1100, 1101, 1110, 1111, 1112, 1120, 1121, 1122, 1123, 1200, 1201, 1210, 1211, 1212, 1220, 1221, 1222, 1223, 1230, 1231, 1232, 1233, 1234, 10000, 10001, 10010, 10011
Offset: 0

Views

Author

N. J. A. Sloane, Apr 06 2014

Keywords

Comments

We write the nonnegative integers as restricted growth strings (so called by J. Arndt in his book fxtbook.pdf, p. 325) in such a way that the Catalan numbers (cf. A000108) are expressed: 1=1, 10=2, 100=5, 1000=14, etc., 10...0 (with k zeros) = the k-th Catalan number. Once the entries of a restricted-growth string grow above 9, one would need commas or parentheses, say, to separate those entries. See Dejter (2017) for the precise definition.
In the paper "A system of numeration for middle-levels", restricted growth strings (RGSs) are defined as sequences that begin with either 0 or 1, with each successive number to the right being at least zero and at most one greater than its immediate left neighbor. Moreover, apart from case a(0), the RGSs are finite integer sequences of restricted growth which always start with 1 as their first element b_1 in position 1, and from then on, each successive element b_{i+1} in the sequence is restricted to be in range [0,(b_i)+1].
This sequence gives all such finite sequences in size-wise and lexicographic order, represented as decimal numbers by concatenating the integers of such finite sequences (e.g., from [1,2,0,1] we get 1201). The 58784th such sequence is [1, 2, 3, 4, 5, 6, 7, 8, 9, 9], thus a(58784) = 1234567899, after which comes the first RGS, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], where an element larger than 9 is present, which means that the decimal system employed here is unambiguous only up to n=58784. Note that 58785 = A000108(11)-1.
Also, if one considers Stanley's interpretation (u) of Catalan numbers, "sequences of a_1, a_2, ..., a_n of integers such that a_1 = 0 and 0 <= a_{i+1} <= a_{i} + 1" (e.g., 000, 001, 010, 011, 012 for C_3), and discards their initial zero, then one has a bijective correspondence with Dejter's RGSs of one element shorter length, which in turn are in bijective correspondence with the first C_n terms of this sequence (by discarding any leading zeros), from a(0) to a(C_n - 1). From this follows that the k-th Catalan number, A000108(k) (k>0), is represented in this system as 1 followed by k-1 zeros: a(1)=1, a(2)=10, a(5)=100, a(14)=1000, etc., and also that there exist exactly A000245(k) RGSs of length k.
Note how this differs from other number representations utilizing Catalan numbers, A014418 and A244159, in that while the latter are base-systems, where a simple weighted Sum_{k} digit(k)*C(k) recovers the natural number n (which the n-th numeral of such system represents), in contrast here it is the sum of appropriate terms in Catalan's Triangle (A009766, A030237), obtained by unranking a unique instance of a certain combinatorial structure (one of the Catalan interpretations), that gives a correspondence with a unique natural number. (Cf. also A014486.)
This sequence differs from "Semigreedy Catalan Representation", A244159, for the first time at n=10, where a(10) = 120, while A244159(10) = 121. That is also the first position where A244158(a(n)) <> n.
Please see Dejter's preprint for a more formal mathematical definition and how this number system is applied in relation to Havel's Conjecture on the existence of Hamiltonian cycles in the middle-levels graphs.
a(n) is given by the concatenation (with leading zeros removed) of the terms of row n + 23714 of A370222. - Paolo Xausa, Feb 17 2024

Examples

			Catalan's Triangle T(row,col) = A009766 begins with row n=0 and 0<=col<=n as:
  Row 0: 1
  Row 1: 1, 1
  Row 2: 1, 2,  2
  Row 3: 1, 3,  5,  5
  Row 4: 1, 4,  9, 14, 14
  Row 5: 1, 5, 14, 28, 42,  42
  Row 6: 1, 6, 20, 48, 90, 132, 132
  (the leftmost diagonal of 1s is "column 0").
  ...
For example, for n=38, we find that A081290(38)=14, which occurs on row A081288(n)-1 = 4, in columns A081288(n)-1 and A081288(n)-2, i.e., as T(4,4) and T(4,3). Thus we subtract 38-14 to get 24, and we see that the next term downward on the same diagonal, 28, is too large to accommodate into the same sum, so we go one diagonal up, starting now from T(3,2) = 5. This fits in, so we now have 24 - 5 = 19, and also the next term on the same diagonal, T(4,2) = 9, fits in, so we now have 19-9 = 10. The next term on the same diagonal, T(5,2) = 14, would not fit in anymore, so we rewind ourselves back to penultimate column, but one step up from where we started on this diagonal, so T(2,1) = 2, which fits in, 10 - 2 = 8, also the next one T(3,1) = 3, 8 - 3 = 5, and the next one T(4,1) = 4, 5 - 4 = 1, after which comes T(5,1) = 5 > 1, thus we jump to T(1,0) = 1, 1-1 = 0, and T(2,0)=1 would not fit anymore, thus next time the row would be zero, and the algorithm is ready with 1 (14), 2 (5+9), 3 (2+3+4) and 1 (1) terms collected, whose total sum 14+5+9+2+3+4+1 = 38, thus a(38) = 1231.
For n=20, the same algorithm results in 1 (14), 1 (5), 0 (not even the first tentative term T(2,1) = 2 from the column 1 would fit, so it is skipped), and from one row higher we get the needed 1 (1), so the total sum of these is 14+5+0+1 = 20, thus a(20) = 1101.
		

References

  • D. E. Knuth, The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, third edition, Addison-Wesley, 1977, p. 192.
  • R. P. Stanley, Enumerative Combinatorics, Cambridge, Vol. 2, 1999, Exercise 19, interpretation (u).

Crossrefs

Cf. A000108 (Catalan numbers), A000245 (their first differences), A009766 (Catalan's triangle), A236855 (the sum of elements in k-th RGS), A236859 (for n>=1, gives the length of the initial ascent 123... in term a(n)), A244159 (different kinds of Catalan number systems).
Other Catalan combinatorial structures represented as integer sequences: A014486/A063171: Dyck words, parenthesizations, etc., A071156/A071158: Similar restricted words encoded with help of A007623 (Integers written in factorial base), A071153/A079436 (Łukasiewicz words).

Programs

  • Julia
    function CatalanNumerals(z)
        z == 0 && return 0
        f(n) = factorial(n)
        t(j, k) = div(f(k+j)*(k-j+1), f(j)*f(k+1))
        k, i = 2, 0
        while z >= t(i, i + 1) i += 1 end
        dig = fill(0, i); dig[1] = 1
        x = z - t(i - 1, i)
        m = i - 1
        while x > 0
            w, s, p = 0, 0, 0
            while w <= x
                p = w
                w += t(m - 1, m + s)
                s += 1
            end
            dig[k] = s - 1
            m -= 1; k += 1; x -= p
        end
        s = ""; for d in dig s *= string(d) end
        parse(Int, s)
    end
    [CatalanNumerals(n) for n in 0:42] |> println # Peter Luschny, Nov 10 2019
    
  • MATLAB
    function [ c ] = catrep(z)
    i=0; x=0; y=0; s=0;
    while z>=(factorial(2*i+1)*(2))/(factorial(i)*factorial(i+2))
    i=i+1;
    end
    y=(factorial(2*i-1)*(2))/(factorial(i-1)*factorial(i+1));
    a=zeros(1,i); a(1,1)=1; k=2; x=z-y; m=1;
    while x>0
    w=0; s=0; p=0;
    while w<=x
    p=w;
    w=w+(factorial(2*i-2*m+s-1)*(s+2))/(factorial(i-1-m)*factorial(i-m+s+1));
    s=s+1;
    end
    m=m+1; a(1,k)=s-1; k=k+1; x=x-p;
    end
    a
    end
    
  • Mathematica
    A239903full = With[{r = 2*Range[2, 11]-1}, Reverse[Map[FromDigits[r-#] &, Rest[Select[Subsets[Range[2, 21], {10}, 125477], Min[r-#] >= 0 &]]]]];
    A239903full[[;;100]] (* Paolo Xausa, Feb 17 2024 *)
  • Maxima
    define (t(j,k), (factorial(k+j)*(k-j+1))/(factorial(j)*factorial(k+1)));
    i:0;
    x:19;
    z:0;y:0;s:0;
    while x>=t(i,i+1) do (i:i+1);
    y:t(i-1,i);a:zeromatrix(1,i);a[1,1]:1;k:2;z:x-y;m:1;
    while (z>0) do (
    w:0,s:0,p=0,
    while (w<=z) do (
    p:w,
    w:w+t(i-1-m,i-m+s),
    s:s+1
    ),
    m:m+1,
    a[1,k]:s-1,k:k+1,
    z:z-p
    );
    print(a);
    
  • PARI
    \\ Valid for n<58786 (=A000108(11)).
    nxt(w)=if(w[1]==#w, vector(#w+1, i, i>#w), my(k=1); while(w[k]>w[k+1], w[k]=0; k++); w[k]++; w)
    seq(n)={my(a=vector(n), w=[1]); a[1]=0; for(i=2, #v, a[i]=fromdigits(Vecrev(w)); w=nxt(w)); a} \\ Andrew Howroyd, Jan 24 2023
  • Scheme
    (define (A239903_only_upto_16794 n) (if (zero? n) n (A235049 (A071159 (A081291 n))))) ;; Gives correct results only up to 16794.
    ;; The following gives correct results all the way up to n=58784.
    (define (A239903 n) (baselist-as-decimal (A239903raw n)))
    (definec (A239903raw n) (if (zero? n) (list) (let loop ((n n) (row (A244160 n)) (col (- (A244160 n) 1)) (srow (- (A244160 n) 1)) (catstring (list 0))) (cond ((or (zero? row) (negative? col)) (reverse! (cdr catstring))) ((> (A009766tr row col) n) (loop n srow (- col 1) (- srow 1) (cons 0 catstring))) (else (loop (- n (A009766tr row col)) (+ row 1) col srow (cons (+ 1 (car catstring)) (cdr catstring))))))))
    (define (baselist-as-decimal lista) (baselist->n 10 lista))
    (define (baselist->n base bex) (let loop ((bex bex) (n 0)) (cond ((null? bex) n) (else (loop (cdr bex) (+ (* n base) (car bex)))))))
    ;; From Antti Karttunen, Apr 14-19 2014
    

Formula

To find an RGS corresponding to natural number n, one first finds a maximum row index k such that T(k,k-1) <= n in the Catalan Triangle (A009766) illustrated in the Example section. Note that as the last two columns of this triangle consist of Catalan numbers (that is, T(k,k-1) = T(k,k) = A000108(k)), it means that the first number to be subtracted from n is A081290(n) which occurs as a penultimate element of the row A081288(n)-1, in the column A081288(n)-2. The unranking algorithm then proceeds diagonally downwards, keeping the column index the same, and incrementing the row index, as long as it will encounter terms such that their total sum stays less than or equal to n.
If the total sum of encountered terms on that diagonal would exceed n, the algorithm jumps back to the penultimate column of the triangle, but one row higher from where it started the last time, and again starts summing the terms as long as the total sum stays <= n.
When the algorithm eventually reaches either row zero or column less than zero, the result will be a list of numbers, each element being the number of terms summed from each diagonal, so that the diagonal first traversed appears as the first 1 (as that first diagonal will never allow more than one term), and the number of terms summed from the last traversed diagonal appears the last number in the list. These lists of numbers are then concatenated together as decimal numbers.
These steps can also be played backwards in order to recover the corresponding decimal integer n from such a list of numbers, giving a "ranking function" which will be the inverse to this "unranking function".
For n=1..16794 (where 16794 = A000108(10)-2), a(n) = A235049(A071159(A081291(n))). - Antti Karttunen, Apr 14 2014
Alternative, simpler description of the algorithm from Antti Karttunen, Apr 21 2014: (Start)
Consider the following square array, which is Catalan triangle A009766 without its rightmost, "duplicate" column, appropriately transposed (cf. also tables A030237, A033184 and A054445):
Row| Terms on that row
---+--------------------------
1 | 1 1 1 1 1 ...
2 | 2 3 4 5 6 ...
3 | 5 9 14 20 27 ...
4 | 14 28 48 75 110 ...
5 | 42 90 165 275 429 ...
6 | 132 297 572 1001 1638 ...
To compute the n-th RGS, search first for the greatest Catalan number C_k which is <= n (this is A081290(n), found as the first term of row A081288(n)-1). Then, by a greedy algorithm, select from each successive row (moving towards the top of table) as many terms from the beginning of that row as will still fit into n, subtracting them from n as you go. The number of terms selected from the beginning of each row gives each element of the n-th RGS, so that the number of terms selected from the topmost row (all 1's) appears as its last element.
(End)

Extensions

Description, formula and examples edited/rewritten by Italo J Dejter, Apr 13 2014 and Antti Karttunen, Apr 18 2014

A071155 The Catalan factorial walks (for each rooted plane tree encoded by A014486) encoded as zero-free numbers in factorial base (A007623).

Original entry on oeis.org

0, 1, 3, 5, 9, 15, 11, 17, 23, 33, 57, 39, 63, 87, 35, 59, 41, 65, 89, 47, 71, 95, 119, 153, 273, 177, 297, 417, 159, 279, 183, 303, 423, 207, 327, 447, 567, 155, 275, 179, 299, 419, 161, 281, 185, 305, 425, 209, 329, 449, 569, 167, 287, 191, 311, 431, 215, 335
Offset: 0

Views

Author

Antti Karttunen, May 14 2002

Keywords

Crossrefs

Same sequence sorted: A071156, expanded in the factorial number system: A071157. Corresponding Łukasiewicz words: A071153.
Cf. A000108 (row lengths), A120695.

A126307 a(n) is the length of the leftmost ascent (i.e., height of the first peak) in the n-th Dyck path encoded by A014486(n).

Original entry on oeis.org

0, 1, 1, 2, 1, 1, 2, 2, 3, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
Offset: 0

Views

Author

Antti Karttunen, Jan 02 2007

Keywords

Comments

In other words, this sequence gives the number of leading 1's in the terms of A063171.

Examples

			A014486(20) = 228 (11100100 in binary), encodes the following Dyck path:
    /\
   /  \/\
  /      \
and the first rising (left-hand side) slope has length 3, thus a(20)=3.
		

Crossrefs

Formula

a(n) = A090996(A014486(n)).
Showing 1-10 of 13 results. Next