login
A101211
Triangle read by rows: n-th row is length of run of leftmost 1's, followed by length of run of 0's, followed by length of run of 1's, etc., in the binary representation of n.
62
1, 1, 1, 2, 1, 2, 1, 1, 1, 2, 1, 3, 1, 3, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 3, 1, 4, 1, 4, 1, 3, 1, 1, 2, 1, 1, 1, 2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 3, 2, 3, 2, 2, 1, 2, 1, 1, 1, 2, 1, 2, 3, 2, 3, 1, 1, 4, 1, 5, 1, 5, 1, 4, 1, 1, 3, 1, 1, 1, 3, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 2, 2, 1
OFFSET
1,4
COMMENTS
Row n has A005811(n) elements. In rows 2^(k-1)..2^k-1 we have all the compositions (ordered partitions) of k. Other orderings of compositions: A066099, A108244, and A124734. - Jason Kimberley, Feb 09 2013
A043276(n) = largest term in n-th row. - Reinhard Zumkeller, Dec 16 2013
From the first comment it follows that we have a bijection between the positive integers and the set of all compositions. - Emeric Deutsch, Jul 11 2017
From Robert Israel, Jan 23 2018: (Start)
If n is even, row 2*n is row n with its last element incremented by 1, and row 2*n+1 is row n with 1 appended.
If n is odd, row 2*n+1 is row n with its last element incremented by 1, and row 2*n is row n with 1 appended. (End)
FORMULA
a(n) = A227736(A227741(n)) = A227186(A056539(A227737(n)),A227740(n)) - Antti Karttunen, Jul 27 2013
EXAMPLE
Since 9 is 1001 in binary, the 9th row is 1,2,1.
Since 11 is 1011 in binary, the 11th row is 1,1,2.
Triangle begins:
1;
1,1;
2;
1,2;
1,1,1;
2,1;
3;
1,3;
MAPLE
# Maple program due to W. Edwin Clark:
Runs := proc (L) local j, r, i, k; j := 1: r[j] := L[1]: for i from 2 to nops(L) do if L[i] = L[i-1] then r[j] := r[j], L[i] else j := j+1: r[j] := L[i] end if end do: [seq([r[k]], k = 1 .. j)] end proc: RunLengths := proc (L) map(nops, Runs(L)) end proc: c := proc (n) ListTools:-Reverse(convert(n, base, 2)): RunLengths(%) end proc: # Row n is obtained with the command c(n). - Emeric Deutsch, Jul 03 2017
# Maple program due to W. Edwin Clark, yielding the integer ind corresponding to a given composition (the index of the composition):
ind := proc (x) local X, j, i: X := NULL: for j to nops(x) do if type(j, odd) then X := X, seq(1, i = 1 .. x[j]) end if: if type(j, even) then X := X, seq(0, i = 1 .. x[j]) end if end do: X := [X]: add(X[i]*2^(nops(X)-i), i = 1 .. nops(X)) end proc; # Clearly, ind(c(n))= n. - Emeric Deutsch, Jan 23 2018
MATHEMATICA
Table[Length /@ Split@ IntegerDigits[n, 2], {n, 38}] // Flatten (* Michael De Vlieger, Jul 11 2017 *)
PROG
(Scheme, two variants)
(define (A101211 n) (A227736 (A227741 n)))
(define (A101211v2 n) (A227186bi (A056539 (A227737 n)) (A227740 n)))
;; Scheme-implementation for A227186bi can be found under A227186. - Antti Karttunen, Jul 27 2013
(Haskell)
import Data.List (group)
a101211 n k = a101211_tabf !! (n-1) !! (k-1)
a101211_row n = a101211_tabf !! (n-1)
a101211_tabf = map (reverse . map length . group) $ tail a030308_tabf
-- Reinhard Zumkeller, Dec 16 2013
(Python)
from itertools import groupby
def arow(n): return [len(list(g)) for k, g in groupby(bin(n)[2:])]
def auptorow(rows):
alst = []
for i in range(1, rows+1): alst.extend(arow(i))
return alst
print(auptorow(38)) # Michael S. Branicky, Oct 02 2021
(PARI) apply( {A101211_row(n, r=[], L=1, D=1)=for(i=2, #n=binary(n), if(n[i]==D, L++, r=concat(r, L); L=1; D=!D)); if(L, concat(r, L), r)}, [1..9]) \\ M. F. Hasler, Mar 11 2025
CROSSREFS
A070939(n) gives the sum of terms in row n, while A167489(n) gives the product of its terms. A090996 gives the first column. A227736 lists the terms of each row in reverse order.
Cf. also A227186.
Cf. A318927 (concatenation of each row), A318926 (concatenations of reversed rows).
Sequence in context: A245548 A025903 A175327 * A329349 A329348 A329344
KEYWORD
nonn,base,tabf,changed
AUTHOR
Leroy Quet, Dec 13 2004
EXTENSIONS
More terms from Emeric Deutsch, Apr 12 2005
STATUS
approved