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

A227192 Sum of the partial sums of the run lengths of binary expansion of n, when starting scanning from the least significant end; Row sums of A227188 and A227738.

Original entry on oeis.org

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

Views

Author

Antti Karttunen, Jul 06 2013

Keywords

Comments

Equivalently, sum of bit-indices in binary expansion of n (counted from the right hand end, with the least significant bit having bit-index 0) of the positions where a bit differs from its immediate right-hand neighbor, counted up to the first leading zero.
a(0) could be 0 or 1, depending on how the binary expansion of zero is conceived, thus its value is left unspecified here.
From Jason Kimberley, Feb 22 2022: (Start)
Also, the total length of string movement required to display the binary expansion of n by the positions of the vanes of vertical blinds (starting with all 0).
The transitions from 0000 to 1011 are:
0001, 0011, 0111, 1111;
1110, 1100, 1000;
The transitions from 0000 to 1101 are:
0001, 0011, 0111, 1111;
1110, 1100;
1101. (End)

Examples

			For 11, whose binary expansion is "1011", the run lengths, when starting scanning from the right, are: [2,1,1]. Their partial sums are [2,2+1,2+1+1] = [2,3,4] which sum to total 9, thus a(11)=9. Equivalently, the zero-based positions (counted from the right) where bits change from one to zero or vice versa in "...01011" are 2, 3, 4 and 2+3+4 = 9.
For 13, whose binary expansion is "1101", the run lengths similarly scanned are [1,1,2]. Their partial sums are [1,1+1,1+1+2] = [1,2,4] which sum to total 7, thus a(13)=7. Equivalently, the positions where bits change in "...01101" are 1, 2, 4 and 1+2+4 = 7.
		

Crossrefs

Cf. A005811, A227183. Row sums of A227188 and A227738.

Programs

  • Mathematica
    Table[Tr[FoldList[Plus,0,Length /@ Split[Reverse[IntegerDigits[n,2]]]] ],{n,71}] (* Wouter Meeussen, Aug 22 2013 *)
  • PARI
    a(n)=local(b,s,t);b=binary(n);s=#b;t=b[#b];forstep(i=#b-1,1,-1,if(b[i]!=t,s=s+#b-i;t=!t));s /* Ralf Stephan, Sep 04 2013 */
    
  • Python
    def A227192(n):
      '''Sum of the partial sums of the run lengths of binary expansion of n, starting from the least significant end.'''
      s = 0
      b = n%2
      i = 0
      while (n != 0):
        n >>= 1
        i += 1
        if((n%2) != b):
          b = n%2
          s += i
      return(s)
    
  • Ruby
    def a(n)
      k = n.to_s(2).scan(/((\d)\2*)/)
      k.each_index.map { |i| (i + 1) * k[i][0].size }.reduce(:+)
    end # Peter Kagey, Aug 06 2015
  • Scheme
    (define (A227192 n) (let loop ((i (- (A005811 n) 1)) (s 0)) (cond ((< i 0) s) (else (loop (- i 1) (+ s (A227188bi n i))))))) ;; This version sums the nonzero terms of the n-th row of table A227188.
    (define (A227192v2 n) (+ (A227183 n) (A000217 (- (A005811 n) 1)))) ;; Another variant.
    (define (A227192v3 n) (add A227738 (+ 1 (A173318 (- n 1))) (A173318 n))) ;; This sums terms of table A227738.
    ;; With the help of this function that implements Sum_{i=lowlim..uplim} intfun(i)
    (define (add intfun lowlim uplim) (let sumloop ((i lowlim) (res 0)) (cond ((> i uplim) res) (else (sumloop (1+ i) (+ res (intfun i)))))))
    

Formula

a(n) = Sum_{i=0..A005811(n)-1} A227188(n,i). [Row sums of A227188]
Equivalently, for n>=1, a(n) = Sum_{i=(A173318(n-1)+1)..A173318(n)} A227738(i). [Row sums of A227738]
a(n) = A227183(n) + A000217(A005811(n)-1). [Alternative definition]
a(n) = A029931(A003188(n)).
Recurrence: a(2n) = a(n) + 2*A069010(n), a(2n+1) = a(2n) +1 or -1, according to if n is even or odd. - Ralf Stephan, Sep 04 2013

A227736 Irregular table read by rows: the first entry of n-th row is length of run of rightmost identical bits (either 0 or 1, equal to n mod 2), followed by length of the next run of bits, etc., in the binary representation of n, when scanned from the least significant to the most significant end.

Original entry on oeis.org

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

Views

Author

Antti Karttunen, Jul 25 2013

Keywords

Comments

Row n has A005811(n) terms. In rows 2^(k-1)..2^k-1 we have all the compositions (ordered partitions) of k. Other orderings of compositions: A101211 (same with rows reversed), A066099, A108244 and A124734.
Each row n >= 1 contains the initial A005811(n) nonzero terms from the beginning of row n of A227186. A070939(n) gives the sum of terms on row n, while A167489(n) gives the product of its terms. A136480 gives the first column. A101211 lists the terms of each row in reverse order.

Examples

			Table begins as:
  Row  n in    Terms on
   n   binary  that row
   1      1    1;
   2     10    1,1;
   3     11    2;
   4    100    2,1;
   5    101    1,1,1;
   6    110    1,2;
   7    111    3;
   8   1000    3,1;
   9   1001    1,2,1;
  10   1010    1,1,1,1;
  11   1011    2,1,1;
  12   1100    2,2;
  13   1101    1,1,2;
  14   1110    1,3;
  15   1111    4;
  16  10000    4,1;
etc. with the terms of row n appearing in reverse order compared how the runs of the same length appear in the binary expansion of n (Cf. A101211).
From _Omar E. Pol_, Sep 08 2013: (Start)
Illustration of initial terms:
  ---------------------------------------
  k   m     Diagram        Composition
  ---------------------------------------
  .          _
  1   1     |_|_           1;
  2   1     |_| |          1, 1,
  2   2     |_ _|_         2;
  3   1     |_  | |        2, 1,
  3   2     |_|_| |        1, 1, 1,
  3   3     |_|   |        1, 2,
  3   4     |_ _ _|_       3;
  4   1     |_    | |      3, 1,
  4   2     |_|_  | |      1, 2, 1,
  4   3     |_| | | |      1, 1, 1, 1,
  4   4     |_ _|_| |      2, 1, 1,
  4   5     |_  |   |      2, 2,
  4   6     |_|_|   |      1, 1, 2,
  4   7     |_|     |      1, 3,
  4   8     |_ _ _ _|_     4;
  5   1     |_      | |    4, 1,
  5   2     |_|_    | |    1, 3, 1,
  5   3     |_| |   | |    1, 1, 2, 1,
  5   4     |_ _|_  | |    2, 2, 1,
  5   5     |_  | | | |    2, 1, 1, 1,
  5   6     |_|_| | | |    1, 1, 1, 1, 1,
  5   7     |_|   | | |    1, 2, 1, 1,
  5   8     |_ _ _|_| |    3, 1, 1,
  5   9     |_    |   |    3, 2,
  5  10     |_|_  |   |    1, 2, 2,
  5  11     |_| | |   |    1, 1, 1, 2,
  5  12     |_ _|_|   |    2, 1, 2,
  5  13     |_  |     |    2, 3,
  5  14     |_|_|     |    1, 1, 3,
  5  15     |_|       |    1, 4,
  5  16     |_ _ _ _ _|    5;
.
Also irregular triangle read by rows in which row k lists the compositions of k, k >= 1.
Triangle begins:
 [1];
 [1,1], [2];
 [2,1], [1,1,1], [1,2],[3];
 [3,1], [1,2,1], [1,1,1,1], [2,1,1], [2,2], [1,1,2], [1,3], [4];
 [4,1], [1,3,1], [1,1,2,1], [2,2,1], [2,1,1,1], [1,1,1,1,1], [1,2,1,1], [3,1,1], [3,2], [1,2,2], [1,1,1,2], [2,1,2], [2,3], [1,1,3], [1,4], [5];
Row k has length A001792(k-1).
Row sums give A001787(k), k >= 1.
(End)
		

Crossrefs

Cf. A227738 and also A227739 for similar table for unordered partitions.
Cf. A101211 (rows in reversed order).

Programs

  • Haskell
    import Data.List (group)
    a227736 n k = a227736_tabf !! (n-1) !! (k-1)
    a227736_row n = a227736_tabf !! (n-1)
    a227736_tabf = map (map length . group) $ tail a030308_tabf
    -- Reinhard Zumkeller, Aug 11 2014
    
  • Mathematica
    Array[Length /@ Reverse@ Split@ IntegerDigits[#, 2] &, 34] // Flatten (* Michael De Vlieger, Dec 11 2020 *)
  • PARI
    apply( {A227736_row(n, r=[1], b=n%2)=while(n\=2, n%2==b && r[#r]++ || [b=1-b, r=concat(r,1)]); r}, [1..22]) \\ M. F. Hasler, Mar 11 2025
    
  • Python
    def A227736_row(n): return[len(list(g))for _,g in groupby(bin(n)[:1:-1])]
    from itertools import groupby # M. F. Hasler, Mar 11 2025
  • Scheme
    (define (A227736 n) (A227186bi (A227737 n) (A227740 n))) ;; The Scheme-function for A227186bi has been given in A227186.
    

Formula

a(n) = A227186(A227737(n), A227740(n)).
a(n) = A101211(A227741(n)).

A227739 Irregular table where row n lists in nondecreasing order the parts of unordered partition encoded in the runlengths of binary expansion of n; nonzero terms of A227189.

Original entry on oeis.org

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

Views

Author

Antti Karttunen, Jul 25 2013

Keywords

Comments

Row n has A005811(n) elements. Each row contains a unique (unordered) partition of some integer, and all possible partitions of finite natural numbers eventually occur. The first partition that sums to k occurs at row A227368(k) and the last at row A000225(k).
Other similar tables of unordered partitions: A036036, A036037, A080576, A080577 and A112798.

Examples

			Rows are constructed as:
  Row    n in   Runlengths  With one     Partial sums   The row sums
   n    binary  collected   subtracted   of which give  to, i.e. is
                from lsb-   from all     terms on       a partition of
                to msb-end  except 1st   that row       of A227183(n)
   1       "1"        [1]        [1]     1;             1
   2      "10"      [1,1]      [1,0]     1, 1;          2
   3      "11"        [2]        [2]     2;             2
   4     "100"      [2,1]      [2,0]     2, 2;          4
   5     "101"    [1,1,1]    [1,0,0]     1, 1, 1;       3
   6     "110"      [1,2]      [1,1]     1, 2;          3
   7     "111"        [3]        [3]     3;             3
   8    "1000"      [3,1]      [3,0]     3, 3;          6
   9    "1001"    [1,2,1]    [1,1,0]     1, 2, 2;       5
  10    "1010"  [1,1,1,1]  [1,0,0,0]     1, 1, 1, 1;    4
  11    "1011"    [2,1,1]    [2,0,0]     2, 2, 2;       6
  12    "1100"      [2,2]      [2,1]     2, 3;          5
  13    "1101"    [1,1,2]    [1,0,1]     1, 1, 2;       4
  14    "1110"      [1,3]      [1,2]     1, 3;          4
  15    "1111"        [4]        [4]     4;             4
  16   "10000"      [4,1]      [4,0]     4, 4;          8
		

Crossrefs

Row sums: A227183, row products: A227184, the initial (smallest) term of each row: A136480, the last (largest) term: A227185.
Cf. also A227189, A227738, A227736.

Programs

  • Mathematica
    Table[Function[b, Accumulate@ Prepend[If[Length@ b > 1, Rest[b] - 1, {}], First@ b]]@ Map[Length, Split@ Reverse@ IntegerDigits[n, 2]], {n, 34}] // Flatten (* Michael De Vlieger, May 09 2017 *)
  • Scheme
    (define (A227739 n) (A227189bi (A227737 n) (A227740 n))) ;; The Scheme-code for A227189bi has been given in A227189.

Formula

a(n) = A227189(A227737(n),A227740(n)).

A227737 n occurs as many times as there are runs in binary representation of n.

Original entry on oeis.org

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

Views

Author

Antti Karttunen, Jul 25 2013

Keywords

Comments

a(n) = the least integer k such that A173318(k) >= n, which implies that each n occurs A005811(n) times.
Although as such quite uninteresting, this sequence is useful for computing irregular tables like A101211, A227736, A227738 and A227739.

Examples

			1 has one run in its binary representation "1", thus 1 occurs once.
2 has two runs in its binary representation "10", thus 2 occurs twice.
3 has one run in its binary representation "11", thus 3 occurs only once.
4 has two runs in its binary representation "100", thus 4 occurs twice.
5 has three runs in its binary representation "101", thus 5 occurs three times.
The sequence thus begins as 1, 2,2, 3, 4,4, 5,5,5, ...
		

Crossrefs

Programs

  • Mathematica
    Table[ConstantArray[n, Length@ Split@ IntegerDigits[n, 2]], {n, 26}] // Flatten (* Michael De Vlieger, May 09 2017 *)
    Table[PadRight[{},Length[Split[IntegerDigits[n,2]]],n],{n,40}]//Flatten (* Harvey P. Dale, Jul 23 2021 *)

A227740 Integers from 0 to A037834(n) followed by integers from 0 to A037834(n+1) and so on.

Original entry on oeis.org

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

Views

Author

Antti Karttunen, Jul 25 2013

Keywords

Comments

Equivalently, integers from 0 to A005811(n)-1 followed by integers from 0 to A005811(n+1)-1 and so on.

Crossrefs

Programs

  • Mathematica
    Table[Range[0, #] &@ Total@ Flatten@ Map[Abs@ Differences@ # &,
    Partition[IntegerDigits[n, 2], 2, 1]], {n, 34}] // Flatten (* Michael De Vlieger, May 09 2017 *)
  • Scheme
    (define (A227740 n) (- n (+ 1 (A173318 (- (A227737 n) 1)))))

Formula

a(n) = n - (1 + A173318(A227737(n)-1)).

A360287 a(n) is the concatenation of the positions of 1-bits in the binary expansion of the Gray code for n, when 1 is the rightmost position; a(0) = 0.

Original entry on oeis.org

0, 1, 12, 2, 23, 123, 13, 3, 34, 134, 1234, 234, 24, 124, 14, 4, 45, 145, 1245, 245, 2345, 12345, 1345, 345, 35, 135, 1235, 235, 25, 125, 15, 5, 56, 156, 1256, 256, 2356, 12356, 1356, 356, 3456, 13456, 123456, 23456, 2456, 12456, 1456, 456, 46, 146, 1246, 246
Offset: 0

Views

Author

Alois P. Heinz, Feb 01 2023

Keywords

Comments

a(n) represents the n-th finite subset of positive integers in Gray order, two consecutive sets differ in exactly one member: {}, {1}, {1,2}, {2}, {2,3}, {1,2,3}, {1,3}, {3}, {3,4}, {1,3,4}, {1,2,3,4}, {2,3,4}, ... .
a(n) is the concatenation of all terms in the n-th row of A227738 (for n>=1).

Examples

			A003188(17) = 25 = 11001_2 gives a(17) = 145.
		

Crossrefs

Programs

  • Maple
    a:= n-> `if`(n=0, 0, (l-> parse(cat(seq(`if`(l[i]=1, i, [][]),
         i=1..nops(l)))))(Bits[Split](Bits[Xor](n, iquo(n, 2))))):
    seq(a(n), n=0..100);

Formula

a(2^n-1) = a(A000225(n)) = n.
a(floor(2^(n+1)/3)) = a(A000975(n)) = A007908(n).

A360289 Number T(n,k) of permutations of [n] whose excedance set is the k-th finite subset of positive integers in Gray order; triangle T(n,k), n>=0, 0<=k<=ceiling(2^(n-1))-1, read by rows.

Original entry on oeis.org

1, 1, 1, 1, 1, 3, 1, 1, 1, 7, 7, 3, 1, 1, 3, 1, 1, 15, 31, 7, 7, 15, 17, 3, 1, 3, 1, 1, 3, 7, 7, 1, 1, 31, 115, 15, 31, 115, 69, 7, 7, 37, 31, 15, 17, 69, 37, 3, 1, 7, 7, 3, 1, 1, 3, 1, 3, 17, 15, 7, 7, 31, 15, 1, 1, 63, 391, 31, 115, 675, 245, 15, 31, 261, 391
Offset: 0

Views

Author

Alois P. Heinz, Feb 01 2023

Keywords

Comments

The list of finite subsets of the positive integers in Gray order begins: {}, {1}, {1,2}, {2}, {2,3}, {1,2,3}, {1,3}, {3}, ... cf. A003188, A227738, A360287.
The excedance set of permutation p of [n] is the set of indices i with p(i)>i, a subset of [n-1].
All terms are odd.

Examples

			T(5,4) = 7: there are 7 permutations of [5] with excedance set {2,3} (the 4th subset in Gray order): 13425, 13524, 13542, 14523, 14532, 15423, 15432.
Triangle T(n,k) begins:
  1;
  1;
  1,  1;
  1,  3,  1, 1;
  1,  7,  7, 3, 1,  1,  3, 1;
  1, 15, 31, 7, 7, 15, 17, 3, 1, 3, 1, 1, 3, 7, 7, 1;
  ...
		

Crossrefs

Columns k=0-1 give: A000012, A000225(n-1) for n>=1.
Row sums give A000142.
Row lengths are A011782.
See A152884, A360288 for similar triangles.

Programs

  • Maple
    a:= n-> `if`(n<2, n, Bits[Xor](n, a(iquo(n, 2)))):
    b:= proc(s, t) option remember; (m->
          `if`(m=0, x^a(t/2), add(b(s minus {i}, t+
          `if`(i (p-> seq(coeff(p, x, i), i=0..degree(p)))(b({$1..n}, 0)):
    seq(T(n), n=0..7);
  • Mathematica
    a[n_] := If[n < 2, n, BitXor[n, a[Quotient[n, 2]]]];
    b[s_, t_] := b[s, t] = With[{m = Length[s]}, If[m == 0, x^a[t/2], Sum[b[s  ~Complement~ {i}, t + If[i < m, 2^i, 0]], {i, s}]]];
    T[n_] := CoefficientList[b[Range[n], 0], x];
    Table[T[n], {n, 0, 7}] // Flatten (* Jean-François Alcover, Dec 09 2023, after Alois P. Heinz *)

A360308 Number T(n,k) of permutations of [n] whose descent set is the k-th finite subset of positive integers in Gray order; triangle T(n,k), n>=0, 0<=k<=ceiling(2^(n-1))-1, read by rows.

Original entry on oeis.org

1, 1, 1, 1, 1, 2, 1, 2, 1, 3, 3, 5, 3, 1, 5, 3, 1, 4, 6, 9, 11, 4, 16, 9, 6, 9, 1, 4, 16, 9, 11, 4, 1, 5, 10, 14, 26, 10, 35, 19, 26, 40, 5, 19, 61, 35, 40, 14, 10, 26, 19, 35, 5, 1, 14, 10, 35, 61, 14, 40, 40, 26, 19, 5, 1, 6, 15, 20, 50, 20, 64, 34, 71, 111
Offset: 0

Views

Author

Alois P. Heinz, Feb 03 2023

Keywords

Comments

The list of finite subsets of the positive integers in Gray order begins: {}, {1}, {1,2}, {2}, {2,3}, {1,2,3}, {1,3}, {3}, ... cf. A003188, A227738, A360287.
The descent set of permutation p of [n] is the set of indices i with p(i)>p(i+1), a subset of [n-1].

Examples

			T(5,5) = 4: there are 4 permutations of [5] with descent set {1,2,3} (the 5th subset in Gray order): 43215, 53214, 54213, 54312.
Triangle T(n,k) begins:
  1;
  1;
  1, 1;
  1, 2, 1, 2;
  1, 3, 3, 5,  3, 1,  5, 3;
  1, 4, 6, 9, 11, 4, 16, 9, 6, 9, 1, 4, 16, 9, 11, 4;
  ...
		

Crossrefs

Row sums give A000142.
Row lengths are A011782.
See A060351, A335845, A357611 for similar triangles (same terms, different ordering within each row).

Programs

  • Maple
    a:= proc(n) a(n):= `if`(n<2, n, Bits[Xor](n, a(iquo(n, 2)))) end:
    b:= proc(u, o, t) option remember; `if`(u+o=0, x^a(t),
          add(b(u-j, o+j-1, t), j=1..u)+
          add(b(u+j-1, o-j, t+2^(o+u-1)), j=1..o))
        end:
    T:= n-> (p-> seq(coeff(p, x, i), i=0..degree(p)))(b(n, 0$2)):
    seq(T(n), n=0..7);
  • Mathematica
    a[n_] := a[n] = If[n<2, n, BitXor[n, a[Quotient[n, 2] ]]];
    b[u_, o_, t_] := b[u, o, t] = If[u + o == 0, x^a[t],        Sum[b[u - j, o + j - 1, t], {j, 1, u}] + Sum[b[u + j - 1, o - j, t + 2^(o + u - 1)], {j, 1, o}]];
    T[n_] := CoefficientList[b[n, 0, 0], x];
    Table[T[n], {n, 0, 7}] // Flatten (* Jean-François Alcover, Feb 14 2023, after Alois P. Heinz *)
Showing 1-8 of 8 results.