OFFSET
0,3
COMMENTS
Leading zeros are taken into account up to the point the number of zeros exceeds the total number of ones.
We scan the binary representation of a number starting from the least significant digit. See A343271 for the other way.
LINKS
FORMULA
EXAMPLE
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
PROG
(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) }
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Apr 09 2021
STATUS
approved