A395179
Maximum number of runs in the binary expansion of integers obtained by changing a single 0-bit to 1 in the binary representation of n considering bits up to and including the first leading 0.
The bit-flip is allowed on any 0-bit within the standard binary representation of n, or on the first implicit leading zero (at position floor(log_2(n)) + 1). This identifies the maximum disruption to the run-length encoding (A005811) caused by a single-bit increment at Hamming distance 1. Therefore, this sequence provides a measure of how a single-bit change at Hamming distance 1 can disrupt the compression efficiency (RLE) of the binary representation of n.
Sequence Chart
Data
Formula
a(n) = max { A005811(n + 2^k) : (n AND 2^k) == 0 and 0 <= k <= floor(log_2(n)) + 1 }.
a(n) = A005811(n) + max { 2*[n in A004779], [n mod 4 == 0] }, where [.] is the Iverson bracket. - _Michael S. Branicky_, Apr 18 2026
Computational Implementations
PYTHON
def count_runs(n):
if n == 0: return 0
s = bin(n)[2:]
runs = 1
for i in range(1, len(s)):
if s[i] != s[i-1]:
runs += 1
return runs
def a(n):
max_r = 0
binary_n = bin(n)[2:]
num_bits = len(binary_n)
for i in range(num_bits):
k = n ^ (1 << i)
if k > n:
max_r = max(max_r, count_runs(k))
k_upper = n ^ (1 << num_bits)
max_r = max(max_r, count_runs(k_upper))
return max_r
print([a(n) for n in range(1, 91)]) CODE
def a(n): return (n^(n>>1)).bit_count() + max(2*int("000" in bin(n)), int(n&3==0))
print([a(n) for n in range(1, 91)]) # _Michael S. Branicky_, Apr 18 2026 Mathematica
A395179[n_] := DigitSum[BitXor[n, Quotient[n, 2]], 2] + If[StringContainsQ[IntegerString[n, 2], "000"], 2, Boole[Divisible[n, 4]]];Array[A395179, 100] (* _Paolo Xausa_, May 04 2026 *) Cross-References
See also OEIS entries: Cf. A394905, A044813, A005811, A004779, A008586.