OFFSET
0,4
COMMENTS
The bit 2^d is set in a(n) iff for some e >= 0, the bits 2^e and 2^(e+d) are set in n.
This sequence has similarities with A067398; here we take the absolute differences, there the sums, of indices of 1's in binary expansions.
All terms are odd, except a(0) = 0.
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)
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 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
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 *)
PROG
(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
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Oct 15 2021
STATUS
approved