A384868 a(n) = Sum_{i=1...|b|} i*(-1)^b_i where b is the lexicographically n-th binary string.
0, 1, -1, 3, -1, 1, -3, 6, 0, 2, -4, 4, -2, 0, -6, 10, 2, 4, -4, 6, -2, 0, -8, 8, 0, 2, -6, 4, -4, -2, -10, 15, 5, 7, -3, 9, -1, 1, -9, 11, 1, 3, -7, 5, -5, -3, -13, 13, 3, 5, -5, 7, -3, -1, -11, 9, -1, 1, -9, 3, -7, -5, -15, 21, 9, 11, -1, 13, 1, 3, -9, 15, 3, 5, -7, 7, -5, -3, -15, 17
Offset: 0
Examples
The lexicographically 8th binary string is 001; therefore, a(8) = 1 + 2 - 3 = 0. Sequence can be written as triangle T(n,k) with row lengths 2^n: 0; 1, -1; 3, -1, 1, -3; 6, 0, 2, -4, 4, -2, 0, -6; 10, 2, 4, -4, 6, -2, 0, -8, 8, 0, 2, -6, 4, -4, -2, -10; ...
Links
- Alois P. Heinz, Table of n, a(n) for n = 0..16383
Programs
-
PARI
a(n) = my(b=[d|d<-binary(n+1)[^1]]); sum(i=1, #b, i*(-1)^b[i]); \\ Michel Marcus, Jun 11 2025
-
Python
from math import comb def A384868(n): return comb(len(s:=bin(n+1)[3:])+1,2)-(sum(i for i,j in enumerate(s,1) if j=='1')<<1) # Chai Wah Wu, Jun 13 2025
-
Python
def a384868(n): return sum(i if b == '0' else -i for i, b in enumerate(bin(n + 1)[3:], 1)) # David Radcliffe, Jun 15 2025
Comments