login
Numbers k such that in the binary expansion of k, the Hamming weight of each block differs by at most 1 from every other block of the same length.
2

%I #10 Oct 13 2022 12:28:16

%S 0,1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,20,21,22,23,26,27,29,30,

%T 31,32,33,34,36,37,41,42,43,45,46,47,53,54,55,59,61,62,63,64,65,66,68,

%U 72,73,74,82,84,85,86,90,91,93,94,95,106,107,109,110,111

%N Numbers k such that in the binary expansion of k, the Hamming weight of each block differs by at most 1 from every other block of the same length.

%C Leading zeros in binary expansions are ignored.

%C For any n > 0, there are A005598(n)/2 positive terms with binary length n.

%C Empirically, if t is a term, then at least one of 2*t or 2*t + 1 is also a term.

%C If t is a term, then floor(t/2) is also a term.

%H Rémy Sigrist, <a href="/A357758/a357758.gp.txt">PARI program</a>

%H <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>

%e For k = 42:

%e - the binary expansion of 42 is "101010",

%e - blocks of length 1 have Hamming weight 0 or 1,

%e - blocks of length 2 have Hamming weight 1,

%e - blocks of length 3 have Hamming weight 1 or 2,

%e - blocks of length 4 have Hamming weight 2,

%e - blocks of length 5 have Hamming weight 2 or 3,

%e - so 42 belongs to the sequence.

%e For k = 44:

%e - the binary expansion of 44 is "101100",

%e - blocks of length 2 have Hamming weight 0, 1 or 2,

%e - so 44 does not belong to the sequence.

%o (PARI) See Links section.

%o (Python)

%o def ok(n):

%o b = bin(n)[2:]

%o if "00" in b and "11" in b: return False

%o for l in range(3, len(b)):

%o h = set(b[i:i+l].count("1") for i in range(len(b)-l+1))

%o if max(h) - min(h) > 1: return False

%o return True

%o print([k for k in range(112) if ok(k)]) # _Michael S. Branicky_, Oct 12 2022

%Y Cf. A005598, A274008, A357759.

%K nonn,base

%O 1,3

%A _Rémy Sigrist_, Oct 12 2022