Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).
%I #24 Jun 14 2024 01:49:18
%S 0,1,2,2,3,2,4,2,3,4,5,2,4,4,6,2,3,4,5,4,5,6,7,2,4,4,6,4,6,6,8,2,3,4,
%T 5,4,5,6,7,4,5,6,7,6,7,8,9,2,4,4,6,4,6,6,8,4,6,6,8,6,8,8,10,2,3,4,5,4,
%U 5,6,7,4,5,6,7,6,7,8,9,4,5,6,7,6,7,8,9,6,7,8
%N Sum of the binary digits of the n-th base-2 palindrome.
%H Robert Israel, <a href="/A043261/b043261.txt">Table of n, a(n) for n = 1..10000</a>
%F Let b(1) = 0, b(2) = 1, otherwise b(2*n-1) = b(n-1) and b(2*n) = b(n).
%F Let c(1) = 0, c(2) = 1, otherwise c(2*n-1) = c(n-1)+1 and c(2*n) = c(n).
%F Then for n >= 2, a(2*n-1) = 2*c(2*n-1) - b(2*n-1) and a(2*n) = 2*c(2*n).
%e The fourth base-2 palindrome is 5 = 101_2, so a(4) = 1+0+1 = 2.
%p b:= proc(n) option remember;
%p procname(floor(n/2)) end proc;
%p b(1):= 0; b(2):= 1;
%p c:= proc(n) option remember;
%p procname(floor(n/2)) + (n mod 2) end proc;
%p c(1):= 0; c(2):= 1;
%p A043261:= n -> 2*c(n) - (n mod 2)*b(n);
%p A043261(2):= 1;# _Robert Israel_, Apr 06 2014
%o (Python)
%o def A043261(n):
%o if n == 1: return 0
%o a = 1<<(l:=n.bit_length()-2)
%o m = a|(n&a-1)
%o return (m.bit_count()<<1) - (0 if a&n else m&1) # _Chai Wah Wu_, Jun 13 2024
%Y Cf. A006995 (base-2 palindromes), A057148.
%K nonn,base
%O 1,3
%A _Clark Kimberling_
%E edited by _Robert Israel_, Apr 06 2014