OFFSET
1,1
COMMENTS
Every term is divisible by 4, since the final 0-run has length at least 2.
For k >= 1, the single-block 1^k 0^(k+1) = 2^(2k+1) - 2^(k+1) = A059153(k-1) is a term.
The function x -> x & (2*x) shortens each 1-run by 1 and lengthens the following 0-run by 1, mapping A387270 termwise onto this sequence.
Transforming each single-block 1^k 0^(k+1) to a digit k, generates a sequence like A069800, but in a different order: for example "5" comes before "1111".
LINKS
Ahmet Caglar Saygili, Table of n, a(n) for n = 1..10000
Sean A. Irvine, Java program (github)
EXAMPLE
36 = 100100_2 is a term since its pairs of (1 then 0) runs are (1,2), (1,2).
MATHEMATICA
Select[Range[4, 30000, 4], AllTrue[Differences[Map[Length, Split[IntegerDigits[#, 2]]]][[;; ;; 2]], # == 1 &] &] (* Paolo Xausa, Oct 22 2025 *)
PROG
(Julia)
function ok(n::Integer)::Bool
n > 0 && iseven(n) || return false
x = unsigned(n)
while x != 0
z = trailing_zeros(x); x >>= z
o = trailing_ones(x)
z == o + 1 || return false
x >>= o
end
true
end
[k for k in 0:10^5 if ok(k)]
(Python)
from itertools import groupby
def ok(n):
L = [len(list(g)) for k, g in groupby(bin(n)[2:])]
return (m:=len(L))&1 == 0 and all(L[2*j]+1 == L[2*j+1] for j in range(m>>1))
print([k for k in range(10**5) if ok(k)]) # Michael S. Branicky, Aug 25 2025
(PARI) isok(k) = if (!(k%2), my(b=binary(k), pos=1, d, dd); for (i=1, #b-1, if (b[i] != b[i+1], if (b[i], d = i-pos+1; pos = i+1, dd = i-pos+1; pos = i+1; if (dd != d+1, return(0))))); dd = #b - pos+1; if (dd != d+1, return(0)); return(1); ); \\ Michel Marcus, Aug 26 2025
(PARI) isok(t)= my(ok=!!t, v); while(t, (ok=((v=valuation(t, 2))>1)) || break; (ok=(bitand(t, 4^v-1) == (2^(v-1)-1)<<v)) || break; t>>=(v*2-1)); ok; \\ Ruud H.G. van Tol, Apr 23 2026
CROSSREFS
KEYWORD
base,nonn,easy
AUTHOR
Ahmet Caglar Saygili, Aug 24 2025
STATUS
approved
