OFFSET
0,4
COMMENTS
Or number of steps it takes to double n, where each step goes to the next larger integer with the same binary weight.
LINKS
Alois P. Heinz, Table of n, a(n) for n = 0..20000
FORMULA
EXAMPLE
a(9) = 4: 9 -> 10 -> 12 -> 17 -> 18 or in binary: 1001_2 -> 1010_2 -> 1100_2 -> 10001_2 -> 10010_2.
MAPLE
b:= proc(n) option remember; uses Bits; local c, l, k;
c, l:= 0, [Split(n)[], 0];
for k while l[k]<>1 or l[k+1]<>0 do c:=c+l[k] od;
Join([1$c, 0$k-c, 1, l[k+2..-1][]])
end:
a:= proc(n) option remember; local i, m, t; m, t:=n, 2*n;
for i from 0 while m<>t do m:= b(m) od; i
end:
seq(a(n), n=0..100);
MATHEMATICA
f[n_] := f[n] = DigitCount[n, 2, 1]; a[n_] := Count[ Array[f, n, n], f[n]]; Array[a, 75, 0] (* Robert G. Wilson v, Mar 15 2023 *)
PROG
(Python)
from math import comb
def A361079(n):
c, k = 0, 1
for i, j in enumerate(bin(n)[-1:1:-1]):
if j == '1':
c += comb(i+1, k)-comb(i, k)
k += 1
return c # Chai Wah Wu, Mar 01 2023
(PARI) a(n) = my(w=hammingweight(n)); sum(k=n, 2*n-1, hammingweight(k) == w); \\ Michel Marcus, Mar 16 2023
CROSSREFS
KEYWORD
AUTHOR
Alois P. Heinz, Mar 01 2023
STATUS
approved