This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A383270 #34 May 07 2025 19:18:45 %S A383270 1,1,2,2,2,3,3,3,2,2,3,4,3,4,4,4,2,2,2,3,3,3,4,5,3,3,4,5,4,5,5,5,2,2, %T A383270 2,3,2,3,3,4,3,3,3,4,4,4,5,6,3,3,3,3,4,4,5,6,4,4,5,6,5,6,6,6,2,2,2,3, %U A383270 2,3,3,4,2,2,3,4,3,4,4,5,3,3,3,3,3,3,4,5 %N A383270 Length of the longest sequence of contiguous 1s in the binary expansion of n after flipping at most one 0-bit to 1. %C A383270 There is only one allowed bit flip from 0 to 1 for each term, unless n is of the form 2^k-1 in which case a(n) = k. %C A383270 At most one bit flip from 0 to 1 is allowed. If the original binary representation already contains the longest run of 1s, no flip is required. %F A383270 a(n) <= 1 + floor(log_2(n)). %F A383270 a(2^k-1) = k. %F A383270 a(2^k) = 2 for k > 0. %F A383270 a(2^k+1) = 2. %F A383270 A038374(n) <= a(n) <= A000120(n)+1. - _Michael S. Branicky_, Apr 21 2025 %e A383270 a(3) = 2 because 3 = 11_2 and there is no need to flip any bit. %e A383270 a(1775) = 8 because 1775 = 11011101111_2 and if we flip the 7th bit we get 1101111111_2 which has the longest sequence of contiguous 1s of length 8. %o A383270 (Python) %o A383270 def a(n): %o A383270 if n == 0: return 1 %o A383270 if n.bit_length() == n.bit_count(): return n.bit_length() %o A383270 c = p = m = 0 %o A383270 while n: %o A383270 if n & 1: c += 1 %o A383270 else: %o A383270 p = c * ((n & 2) > 0) %o A383270 c = 0 %o A383270 if (pc := p + c) > m: m = pc %o A383270 n >>= 1 %o A383270 return m + 1 %o A383270 print([a(n) for n in range(1,88)]) %o A383270 (PARI) a(n) = if (n==0, return(1)); my(b=binary(n), vz = select(x->(x==0), b, 1), m=0); if (#vz <= 1, return (#b)); vz = concat(0, concat(Vec(vz), #b+1)); for (i=1, #vz-2, m = max(m, vz[i+2]-vz[i]-1)); m; \\ _Michel Marcus_, May 02 2025 %Y A383270 Cf. A000079, A000120, A007088, A070939, A038374. %K A383270 nonn,base %O A383270 0,3 %A A383270 _DarĂo Clavijo_, Apr 21 2025