A343049 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).
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, 127, 24, 125, 126, 511, 0, 1, 2, 39, 0, 37, 38, 127, 0, 41, 42, 127, 40, 125, 126, 511, 0, 33, 34, 119, 32, 117, 118, 511, 32, 121, 122, 511, 120, 509, 510, 2047, 0
Offset: 0
Examples
The first terms, in decimal and in binary, are: n a(n) bin(n) bin(a(n)) -- ---- ------ --------- 0 0 0 0 1 1 1 1 2 2 10 10 3 7 11 111 4 0 100 0 5 5 101 101 6 6 110 110 7 31 111 11111 8 0 1000 0 9 9 1001 1001 10 10 1010 1010 11 31 1011 11111 12 8 1100 1000 13 29 1101 11101 14 30 1110 11110 15 127 1111 1111111
Links
Programs
-
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) }
Comments