login
The k-th binary digit of a(n) is the most frequent digit among the first k binary digits of n (in case of a tie, take the k-th binary digit of n).
2

%I #12 Apr 10 2021 10:35:25

%S 0,1,2,7,0,5,6,31,0,9,10,31,8,29,30,127,0,1,2,23,0,21,22,127,0,25,26,

%T 127,24,125,126,511,0,1,2,39,0,37,38,127,0,41,42,127,40,125,126,511,0,

%U 33,34,119,32,117,118,511,32,121,122,511,120,509,510,2047,0

%N The k-th binary digit of a(n) is the most frequent digit among the first k binary digits of n (in case of a tie, take the k-th binary digit of n).

%C Leading zeros are taken into account up to the point the number of zeros exceeds the total number of ones.

%C We scan the binary representation of a number starting from the least significant digit. See A343271 for the other way.

%H Rémy Sigrist, <a href="/A343049/b343049.txt">Table of n, a(n) for n = 0..8192</a>

%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>

%F a(n) = 0 iff n belongs to A036993.

%F a(n) = n iff n = 0 or n belongs to A032925.

%F a(2^k-1) = 2^(2*k-1)-1 for any k > 1.

%F A070939(a(n)) < 2*A070939(n).

%e The first terms, in decimal and in binary, are:

%e n a(n) bin(n) bin(a(n))

%e -- ---- ------ ---------

%e 0 0 0 0

%e 1 1 1 1

%e 2 2 10 10

%e 3 7 11 111

%e 4 0 100 0

%e 5 5 101 101

%e 6 6 110 110

%e 7 31 111 11111

%e 8 0 1000 0

%e 9 9 1001 1001

%e 10 10 1010 1010

%e 11 31 1011 11111

%e 12 8 1100 1000

%e 13 29 1101 11101

%e 14 30 1110 11110

%e 15 127 1111 1111111

%o (PARI) a(n, base=2) = { my (d=digits(n, base), t, f=vector(base)); d=concat(vector(#d), d); forstep (k=#d, 1, -1, f[1+d[k]]++; if (vecmax(f)==f[1+d[k]], t=d[k];); d[k]=t); fromdigits(d, base) }

%Y Cf. A032925, A036993, A070939, A343271, A342697.

%K nonn,base

%O 0,3

%A _Rémy Sigrist_, Apr 09 2021