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-6 of 6 results.

A057163 Signature-permutation of a Catalan automorphism: Reflect a rooted plane binary tree; Deutsch's 1998 involution on Dyck paths.

Original entry on oeis.org

0, 1, 3, 2, 8, 7, 6, 5, 4, 22, 21, 20, 18, 17, 19, 16, 15, 13, 12, 14, 11, 10, 9, 64, 63, 62, 59, 58, 61, 57, 55, 50, 49, 54, 48, 46, 45, 60, 56, 53, 47, 44, 52, 43, 41, 36, 35, 40, 34, 32, 31, 51, 42, 39, 33, 30, 38, 29, 27, 26, 37, 28, 25, 24, 23, 196, 195, 194, 190, 189
Offset: 0

Views

Author

Antti Karttunen, Aug 18 2000

Keywords

Comments

Deutsch shows in his 1999 paper that this automorphism maps the number of doublerises of Dyck paths to number of valleys and height of the first peak to the number of returns, i.e., that A126306(n) = A127284(a(n)) and A126307(n) = A057515(a(n)) hold for all n.
The A000108(n-2) n-gon triangularizations can be reflected over n axes of symmetry, which all can be generated by appropriate compositions of the permutations A057161/A057162 and A057163.
Composition with A057164 gives signature permutation for Donaghey's Map M (A057505/A057506). Embeds into itself in scale n:2n+1 as a(n) = A083928(a(A080298(n))). A127302(a(n)) = A127302(n) and A057123(A057163(n)) = A057164(A057123(n)) hold for all n.

Examples

			This involution (self-inverse permutation) of natural numbers is induced when we reflect the rooted plane binary trees encoded by A014486. E.g., we have A014486(5) = 44 (101100 in binary), A014486(7) = 52 (110100 in binary) and these encode the following rooted plane binary trees, which are reflections of each other:
    0   0             0   0
     \ /               \ /
      1   0         0   1
       \ /           \ /
    0   1             1   0
     \ /               \ /
      1                 1
thus a(5)=7 and a(7)=5.
		

Crossrefs

This automorphism conjugates between the car/cdr-flipped variants of other automorphisms, e.g., A057162(n) = a(A057161(a(n))), A069768(n) = a(A069767(a(n))), A069769(n) = a(A057508(a(n))), A069773(n) = a(A057501(a(n))), A069774(n) = a(A057502(a(n))), A069775(n) = a(A057509(a(n))), A069776(n) = a(A057510(a(n))), A069787(n) = a(A057164(a(n))).
Row 1 of tables A122201 and A122202, that is, obtained with FORK (and KROF) transformation from even simpler automorphism *A069770. Cf. A122351.

Programs

  • Maple
    a(n) = A080300(ReflectBinTree(A014486(n)))
    ReflectBinTree := n -> ReflectBinTree2(n)/2; ReflectBinTree2 := n -> (`if`((0 = n),n,ReflectBinTreeAux(A030101(n))));
    ReflectBinTreeAux := proc(n) local a,b; a := ReflectBinTree2(BinTreeLeftBranch(n)); b := ReflectBinTree2(BinTreeRightBranch(n)); RETURN((2^(A070939(b)+A070939(a))) + (b * (2^(A070939(a)))) + a); end;
    NextSubBinTree := proc(nn) local n,z,c; n := nn; c := 0; z := 0; while(c < 1) do z := 2*z + (n mod 2); c := c + (-1)^n; n := floor(n/2); od; RETURN(z); end;
    BinTreeLeftBranch := n -> NextSubBinTree(floor(n/2));
    BinTreeRightBranch := n -> NextSubBinTree(floor(n/(2^(1+A070939(BinTreeLeftBranch(n))))));
  • Mathematica
    A014486Q[0] = True; A014486Q[n_] := Catch[Fold[If[# < 0, Throw[False], If[#2 == 0, # - 1, # + 1]] &, 0, IntegerDigits[n, 2]] == 0]; tree[n_] := Block[{func, num = Append[IntegerDigits[n, 2], 0]}, func := If[num[[1]] == 0, num = Drop[num, 1]; 0, num = Drop[num, 1]; 1[func, func]]; func]; A057163L[n_] := Function[x, FirstPosition[x, FromDigits[Most@Cases[tree[#] /. 1 -> Reverse@*1, 0 | 1, All, Heads -> True], 2]][[1]] - 1 & /@ x][Select[Range[0, 2^n], A014486Q]]; A057163L[11] (* JungHwan Min, Dec 11 2016 *)

Formula

a(n) = A083927(A057164(A057123(n))).

Extensions

Equivalence with Deutsch's 1998 involution realized Dec 15 2006 and entry edited accordingly by Antti Karttunen, Jan 16 2007

A099563 a(0) = 0; for n > 0, a(n) = final nonzero number in the sequence n, f(n,2), f(f(n,2),3), f(f(f(n,2),3),4),..., where f(n,d) = floor(n/d); the most significant digit in the factorial base representation of n.

Original entry on oeis.org

0, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
Offset: 0

Views

Author

John W. Layman, Oct 22 2004

Keywords

Comments

Records in {a(n)} occur at {1,4,18,96,600,4320,35280,322560,3265920,...}, which appears to be n*n! = A001563(n).
The most significant digit in the factorial expansion of n (A007623). Proof: The algorithm that computes the factorial expansion of n, generates the successive digits by repeatedly dividing the previous quotient with successively larger divisors (the remainders give the digits), starting from n itself and divisor 2. As a corollary we find that A001563 indeed gives the positions of the records. - Antti Karttunen, Jan 01 2007.

Examples

			For n=15, f(15,2) = floor(15/2)=7, f(7,3)=2, f(2,4)=0, so a(15)=2.
From _Antti Karttunen_, Dec 24 2015: (Start)
Example illustrating the role of this sequence in factorial base representation:
   n  A007623(n)       a(n) [= the most significant digit].
   0 =   0               0
   1 =   1               1
   2 =  10               1
   3 =  11               1
   4 =  20               2
   5 =  21               2
   6 = 100               1
   7 = 101               1
   8 = 110               1
   9 = 111               1
  10 = 120               1
  11 = 121               1
  12 = 200               2
  13 = 201               2
  14 = 210               2
  15 = 211               2
  16 = 220               2
  17 = 221               2
  18 = 300               3
  etc.
Note that there is no any upper bound for the size of digits in this representation.
(End)
		

Crossrefs

Programs

  • Mathematica
    Table[Floor[n/#] &@ (k = 1; While[(k + 1)! <= n, k++]; k!), {n, 0, 120}] (* Michael De Vlieger, Aug 30 2016 *)
  • PARI
    A099563(n) = { my(i=2,dig=0); until(0==n, dig = n % i; n = (n - dig)/i; i++); return(dig); }; \\ Antti Karttunen, Dec 24 2015
    
  • Python
    def a(n):
        i=2
        d=0
        while n:
            d=n%i
            n=(n - d)//i
            i+=1
        return d
    print([a(n) for n in range(201)]) # Indranil Ghosh, Jun 21 2017, after PARI code
  • Scheme
    (define (A099563 n) (let loop ((n n) (i 2)) (let* ((dig (modulo n i)) (next-n (/ (- n dig) i))) (if (zero? next-n) dig (loop next-n (+ 1 i))))))
    (definec (A099563 n) (cond ((zero? n) n) ((= 1 (A265333 n)) 1) (else (+ 1 (A099563 (A257684 n)))))) ;; Based on given recurrence, using the memoization-macro definec
    ;; Antti Karttunen, Dec 24-25 2015
    

Formula

From Antti Karttunen, Dec 25 2015: (Start)
a(0) = 0; for n >= 1, if A265333(n) = 1 [when n is one of the terms of A265334], a(n) = 1, otherwise 1 + a(A257684(n)).
Other identities. For all n >= 0:
a(A001563(n)) = n. [Sequence works as a left inverse for A001563.]
a(n) = A257686(n) / A048764(n).
(End)

Extensions

a(0) = 0 prepended and the alternative description added to the name-field by Antti Karttunen, Dec 24 2015

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

A125985 Signature-permutation of Vaillé's 1997 bijection on 'bridges' (Dyck paths).

Original entry on oeis.org

0, 1, 3, 2, 8, 7, 5, 6, 4, 22, 21, 18, 20, 17, 13, 12, 19, 15, 16, 10, 11, 14, 9, 64, 63, 59, 62, 58, 50, 49, 61, 55, 57, 46, 48, 54, 45, 36, 35, 32, 34, 31, 60, 56, 41, 52, 40, 47, 53, 43, 44, 27, 26, 33, 29, 30, 51, 38, 39, 42, 24, 25, 28, 37, 23, 196, 195, 190, 194, 189
Offset: 0

Views

Author

Antti Karttunen, Jan 02 2007

Keywords

Comments

Vaillé shows in 1997 paper that this automorphism transforms a 'derivation' of a Dyck path to its 'compression', i.e., in OEIS terms, A125985(A126310(n)) = A126309(A125985(n)) holds for all n. He also proves that A057515(A125985(n)) = A126307(n) and A057514(A125985(n)) = A072643(n) - A057514(n) + 1 (the latter identity for all n >= 1).

Crossrefs

Inverse: A125986. The number of cycles, maximum cycle sizes and LCM's of all cycle sizes in range [A014137(n-1)..A014138(n-1)] of this permutation are given by A126291, A126292 and A126293. The fixed points are given by A126300/A126301.

Programs

  • Scheme
    (define (A125985 n) (A080300 (rising-list->binexp (A125985-aux2 (A014486 n)))))
    (define (A125985-aux2 n) (let loop ((lists (A125985-aux1 n)) (z (list)) (m 1)) (if (null? lists) z (loop (cdr lists) (m-join z (car lists) m) (+ m 1)))))
    (define (A125985-aux1 n) (if (zero? n) (list) (let ((begin_from (<< 1 (- (- (A000523 n) (A090996 n)) 1)))) (let loop ((s (A090996 n)) (t 0) (nth_list 1) (p begin_from) (b (if (= 0 (A004198bi n begin_from)) 0 1)) (lists (list (list)))) (cond ((< s 1) (cond ((< p 1) (reverse! lists)) (else (loop (- t (- 1 b)) b (+ 1 nth_list) (>> p 1) (if (= 0 (A004198bi n (>> p 1))) 0 1) (cons (list (+ b 1 nth_list)) lists))))) (else (loop (- s (- 1 b)) (+ t b) nth_list (>> p 1) (if (= 0 (A004198bi n (>> p 1))) 0 1) (cons (cons (+ b nth_list) (car lists)) (cdr lists)))))))))
    (define (A125985-aux2 n) (let loop ((lists (A125985-aux1 n)) (z (list)) (m 1)) (if (null? lists) z (loop (cdr lists) (m-join z (car lists) m) (+ m 1)))))
    (define (m-join a b m) (let loop ((a a) (b b) (c (list))) (cond ((and (not (pair? a)) (not (pair? b))) (reverse! c)) ((not (pair? a)) (loop a (cdr b) (cons (car b) c))) ((not (pair? b)) (loop (cdr a) b (cons (car a) c))) ((equal? (car a) (car b)) (loop (cdr a) (cdr b) (cons (car a) c))) ((> (car b) m) (loop a (cdr b) (cons (car b) c))) (else (loop (cdr a) b (cons (car a) c))))))
    (define (rising-list->binexp rising-list) (let loop ((s 0) (i 0) (h 0) (fs rising-list)) (cond ((null? fs) (+ s (<< (- (<< 1 h) 1) i))) ((> (car fs) h) (loop s (+ i 1) (car fs) (cdr fs))) (else (loop (+ s (<< (- (<< 1 (+ 1 (- h (car fs)))) 1) i)) (+ i 2 (- h (car fs))) (car fs) (cdr fs))))))
    (define (>> n i) (if (zero? i) n (>> (floor->exact (/ n 2)) (- i 1))))
    (define (<< n i) (if (<= i 0) (>> n (- i)) (<< (+ n n) (- i 1))))

A244160 a(0)=0, and for n >= 1, a(n) = the largest k such that k-th Catalan number <= n.

Original entry on oeis.org

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

Views

Author

Antti Karttunen, Jun 23 2014

Keywords

Comments

Apart from 0, each n occurs A000245(n) times.
For n >= 1, a(n) gives the largest k such that C(k) <= n, where C(k) stands for the k-th Catalan number, A000108(k).

Examples

			For n=1, the largest k such that C(k) <= 1 is 1, thus a(1) = 1.
For n=2, the largest k such that C(k) <= 2 is 2, thus a(2) = 2.
For n=3, the largest k such that C(k) <= 3 is 2, thus a(3) = 2.
For n=4, the largest k such that C(k) <= 4 is 2, thus a(4) = 2.
For n=5, the largest k such that C(k) <= 5 is 3, thus a(5) = 3.
		

Crossrefs

After zero, one less than A081288.

Programs

  • Mathematica
    MapIndexed[ConstantArray[First@ #2 - 1, #1] &, Differences@ Array[CatalanNumber, 8, 0]] /. {} -> {0} // Flatten (* Michael De Vlieger, Jun 08 2017 *)
    Join[{0},Table[PadRight[{},CatalanNumber[n+1]-CatalanNumber[n],n],{n,6}]// Flatten] (* Harvey P. Dale, Aug 23 2021 *)
  • Python
    from sympy import catalan
    def a(n):
        if n==0: return 0
        i=1
        while True:
            if catalan(i)>n: break
            else: i+=1
        return i - 1
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 08 2017
  • Scheme
    (define (A244160 n) (if (zero? n) n (- (A081288 n) 1)))
    

Formula

a(0) = 0, and for n>=1, a(n) = A081288(n)-1.
For all n>=1, A000108(a(n)) = A081290(n).

A236859 The length of the initial ascent 123... in the n-th Catalan numeral, A239903(n).

Original entry on oeis.org

0, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 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, 1, 1, 1, 1, 1, 2, 2, 2, 2
Offset: 0

Views

Author

Antti Karttunen, Apr 18 2014

Keywords

Examples

			A239903(1) = 1, thus a(1) = 1.
A239903(2) = 10, thus a(2) = 1.
A239903(4) = 12, thus a(4) = 2.
A239903(39) = 1232, thus a(39) = 3.
A239903(58784) = 1234567899, thus a(58784) = 9.
Note that although the range of validity of A239903 is inherently limited by the decimal representation employed, it doesn't matter here: We have a(58785) = 10, as the corresponding 58785th Catalan String is [1,2,3,4,5,6,7,8,9,10], even though A239903 cannot represent that unambiguously.
		

Crossrefs

Programs

Formula

a(0) = 0, and for n>=1, a(n) = A126307(A081291(n))-1.
Each n occurs for the first time (as a record) at the position (C_{n+1})-1, so we have a(A001453(n+1)) = n for all n.
Showing 1-6 of 6 results.