OFFSET
0,3
LINKS
FORMULA
EXAMPLE
n: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
binary expansion: 0, 1, 10, 11, 100, 101, 110, 111,1000,1001,1010,1011,1100,1101,1110,1111
reversed/complemented: 0, 1, 10, 11, 110, 101, 100, 111,1110,1001,1010,1101,1100,1011,1000,1111
MAPLE
[seq(runcounts2binexp(reverse(binexp2runcounts(j))), j=0..511)];
runcounts2binexp := proc(c) local i, e, n; n := 0; for i from 1 to nops(c) do e := c[i]; n := ((2^e)*n) + ((i mod 2)*((2^e)-1)); od; RETURN(n); end;
binexp2runcounts := proc(nn) local n, a, p, c; n := nn; a := []; p := (`mod`(n, 2)); c := 0; while(n > 0) do c := c+1; n := floor(n/2); if((`mod`(n, 2)) <> p) then a := [c, op(a)]; c := 0; p := (`mod`(p+1, 2)); fi; od; RETURN(a); end;
# reverse given in A056538
PROG
(Python)
def a005811(n): return bin(n^(n>>1))[2:].count("1")
def a(n):
if n==0: return 0
x=bin(n)[2:][::-1]
if a005811(n)%2==1: return int(x, 2)
z=''.join('1' if i == '0' else '0' for i in x)
return int(z, 2) # Indranil Ghosh, Apr 29 2017
CROSSREFS
KEYWORD
AUTHOR
Antti Karttunen, Jun 20, 2000
STATUS
approved