login
A370470
In the binary expansion of n, change the i-th run length to the difference of the i-th and (i-1)-th run lengths. The first run length remains as is.
1
1, 1, 3, 2, 1, 6, 7, 4, 5, 1, 3, 3, 6, 28, 15, 8, 19, 5, 2, 2, 1, 6, 7, 6, 7, 6, 13, 14, 28, 120, 31, 16, 71, 19, 9, 10, 5, 4, 5, 4, 5, 1, 3, 3, 6, 28, 15, 12, 27, 7, 3, 12, 6, 26, 27, 7, 29, 28, 57, 60, 120, 496, 63, 32, 271, 71, 35, 38, 19, 18, 4, 20, 21, 5
OFFSET
1,3
LINKS
Michael De Vlieger, Plot bits of a(n), n = 1..4096, with the least bit at bottom and greatest bit at top, with 1s in black and 0s in white.
Michael De Vlieger, Fan style binary tree for a(n), n = 1..8192, with a color function showing binary weight, where red represents 1 and darkest blue 13.
FORMULA
a(2^j-1) = 2^j-1, as there is only one run.
a(2^j-2) = (2^(j-1)-1)*(2^(j-2)).
a(5*2^k+r) = a(2^k+r) for 0 <= r < 2^k; i.e., appending a '10' to the start of the binary expansion has no effect on the value.
EXAMPLE
Consider n = 988:
binary(n) 1111 0 111 00
run_length 4 1 3 2
modified run_length 4 3 2 1
binary(a(n)) 1111 000 11 0
a(n) = 966.
MATHEMATICA
Array[FromDigits[Flatten@ MapIndexed[ConstantArray[Mod[First[#2], 2], #1] &, Prepend[Abs@ Differences[#], First[#]]], 2] &@ Map[Length, Split[IntegerDigits[#, 2]]] &, 120] (* Michael De Vlieger, Apr 19 2024 *)
PROG
(Python)
def A370470(n):
s = bin(n)[2:]
run_length = 0
runs = []
last_char = '2'
for j in range(len(s)):
if(s[j] != last_char):
last_char = s[j]
runs.append(run_length)
run_length = 1
else:
run_length+=1
runs.append(run_length)
k = ''
for j in range(1, len(runs)):
k+=str(chr(ord('0')+(j%2)))*abs(runs[j]-runs[j-1])
return int(k, 2)
(Python)
from itertools import groupby
def a(n):
r = [len(list(g)) for k, g in groupby(bin(n)[2:])]
return int("1"*r[0]+"".join(str(i&1)*abs(r[i+1]-r[i]) for i in range(len(r)-1)), 2)
print([a(n) for n in range(1, 64)]) # Michael S. Branicky, Apr 10 2024
CROSSREFS
Run lengths are as in A101211.
Sequence in context: A139624 A132276 A257558 * A202390 A210858 A114586
KEYWORD
nonn,base
AUTHOR
Aritra Mitra, Mar 30 2024
EXTENSIONS
More terms from Michael De Vlieger, Apr 19 2024
STATUS
approved