login
Irregular table, where row n (n >= 0) starts with n, the next term is n-A000120(n), and the successive terms are obtained by repeatedly subtracting the number of 1's in the previous term's binary expansion, until zero is reached, after which the next row starts with one larger n.
12

%I #36 Dec 13 2023 20:32:56

%S 0,1,0,2,1,0,3,1,0,4,3,1,0,5,3,1,0,6,4,3,1,0,7,4,3,1,0,8,7,4,3,1,0,9,

%T 7,4,3,1,0,10,8,7,4,3,1,0,11,8,7,4,3,1,0,12,10,8,7,4,3,1,0,13,10,8,7,

%U 4,3,1,0,14,11,8,7,4,3,1,0,15,11,8,7,4,3,1,0

%N Irregular table, where row n (n >= 0) starts with n, the next term is n-A000120(n), and the successive terms are obtained by repeatedly subtracting the number of 1's in the previous term's binary expansion, until zero is reached, after which the next row starts with one larger n.

%H Antti Karttunen, <a href="/A218254/b218254.txt">Rows 0..255, flattened</a>

%e The n-th row (starting indexing from zero) in this irregular table consists of block of length A071542(n)+1: 1,2,3,3,4,4,5,5,... which always ends with zero, as:

%e 0

%e 1,0

%e 2,1,0

%e 3,1,0

%e 4,3,1,0

%e 5,3,1,0

%e 6,4,3,1,0

%e 7,4,3,1,0

%e The 17th term is 6, which in binary is 110. The 18th term is then 6-2=4.

%o (MIT/GNU Scheme)

%o ;; with _Antti Karttunen_'s intseq additions:

%o (definec (A218254 n) (cond ((< n 2) n) ((not (zero? (A218254 (- n 1)))) (- (A218254 (- n 1)) (A000120 (A218254 (- n 1))))) (else (+ 1 (A218254 (+ 1 (Apos_of_prev_zero (- n 1))))))))

%o ;; The following is an auxiliary function not submitted as a separate entry:

%o (define Apos_of_prev_zero (compose-funs A213707 -1+ (LEAST-GTE-I 0 0 A213707)))

%o (PARI) for(n=0,9,k=n;while(k, print1(k", "); k-=hammingweight(k)); print1("0, ")) \\ _Charles R Greathouse IV_, Oct 30 2012

%Y Cf. A218252, A218253. A213707 gives the positions of zeros (i.e. the ending index of each row). A071542, A000120.

%Y The reversed tails of the rows converge towards A179016.

%K nonn,tabf,easy

%O 0,4

%A _Nico Brown_, Oct 24 2012