A089309 Write n in binary; a(n) = length of the rightmost run of 1's.
0, 1, 1, 2, 1, 1, 2, 3, 1, 1, 1, 2, 2, 1, 3, 4, 1, 1, 1, 2, 1, 1, 2, 3, 2, 1, 1, 2, 3, 1, 4, 5, 1, 1, 1, 2, 1, 1, 2, 3, 1, 1, 1, 2, 2, 1, 3, 4, 2, 1, 1, 2, 1, 1, 2, 3, 3, 1, 1, 2, 4, 1, 5, 6, 1, 1, 1, 2, 1, 1, 2, 3, 1, 1, 1, 2, 2, 1, 3, 4, 1, 1, 1, 2, 1, 1, 2, 3, 2, 1, 1, 2, 3, 1, 4, 5, 2, 1, 1, 2, 1, 1, 2, 3, 1
Offset: 0
Examples
13 = 1101 so a(13) = 1.
Links
- Alois P. Heinz, Table of n, a(n) for n = 0..16384
- Francis Laclé, 2-adic parity explorations of the 3n+ 1 problem, hal-03201180v2 [cs.DM], 2021.
- Index entries for sequences related to binary expansion of n
Programs
-
Maple
a := proc(n) if n = 0 then 0 elif `mod`(n, 2) = 0 then a((1/2)*n) elif `mod`(n, 4) = 1 then 1 else 1+a((1/2)*n-1/2) end if end proc: seq(a(n), n = 0 .. 104); # Emeric Deutsch, Aug 17 2017
-
Mathematica
Table[If[n == 0, 0, Length@ Last@ Select[Split@ IntegerDigits[n, 2], First@ # == 1 &]], {n, 0, 104}] (* Michael De Vlieger, Aug 17 2017 *)
-
PARI
a(n) = if (n==0, 0, valuation(n/2^valuation(n, 2)+1, 2)); \\ Ralf Stephan, Aug 31 2013; Michel Marcus, Apr 30 2020
-
Python
def A089309(n): return (~((m:=n>>(~n&n-1).bit_length())+1)&m).bit_length() # Chai Wah Wu, Jul 13 2022
Formula
a(0) = 0, a(2*n) = a(n), a(4*n+1) = 1, a(4*n+3) = 1 + a(2*n+1) (the Maple program makes use of these equations). - Emeric Deutsch, Aug 17 2017
Extensions
More terms from Vladeta Jovovic and John W. Layman, Jan 21 2004
Comments