A348363 The 1's in the binary expansion of a(n) encode the distances between the 1's in the binary expansion of n.
0, 1, 1, 3, 1, 5, 3, 7, 1, 9, 5, 15, 3, 15, 7, 15, 1, 17, 9, 27, 5, 21, 15, 31, 3, 27, 15, 31, 7, 31, 15, 31, 1, 33, 17, 51, 9, 45, 27, 63, 5, 45, 21, 63, 15, 47, 31, 63, 3, 51, 27, 59, 15, 63, 31, 63, 7, 63, 31, 63, 15, 63, 31, 63, 1, 65, 33, 99, 17, 85, 51
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 1 10 1 3 3 11 11 4 1 100 1 5 5 101 101 6 3 110 11 7 7 111 111 8 1 1000 1 9 9 1001 1001 10 5 1010 101 11 15 1011 1111 12 3 1100 11 13 15 1101 1111 14 7 1110 111 15 15 1111 1111
Links
- Rémy Sigrist, Table of n, a(n) for n = 0..8192
- Rémy Sigrist, Colored scatterplot of the first 2^20 terms (where the color is function of the 2-adic valuation of n, upper red pixels correspond to odd n's)
- Index entries for sequences related to binary expansion of n
Programs
-
Mathematica
{0}~Join~Array[Total[2^Append[Union@ Abs[Subtract @@@ Permutations[1 + Length[#] - Position[#, 1][[All, 1]] &@ IntegerDigits[#, 2], {2}]], 0]] &, 70] (* Michael De Vlieger, Oct 16 2021 *)
-
PARI
a(n) = { my (b=vector(hammingweight(n))); for (k=1, #b, n-=2^b[k]=valuation(n, 2);); my (p=setbinop((i,j)->abs(i-j), b)); sum (k=1, #p, 2^p[k]) }
-
Python
def a(n): locs = [e for e in range(n.bit_length()) if 1 & (n>>e)] diffs = set(abs(e1-e2) for i, e1 in enumerate(locs) for e2 in locs[i:]) return sum(2**d for d in diffs) print([a(n) for n in range(71)]) # Michael S. Branicky, Oct 16 2021
Comments