login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A044888 Numbers whose base-2 run lengths alternate: even, odd, even, ... 1

%I #24 Apr 13 2021 23:17:15

%S 3,6,15,24,27,30,54,63,96,99,111,120,123,126,198,216,219,222,246,255,

%T 384,387,399,438,447,480,483,495,504,507,510,774,792,795,798,864,867,

%U 879,888,891,894,966,984,987,990,1014,1023,1536

%N Numbers whose base-2 run lengths alternate: even, odd, even, ...

%C From _Emeric Deutsch_, Jan 27 2018: (Start)

%C Also the indices of the compositions whose parts alternate: even, odd, even, ... . For the definition of the index of a composition see A298644.

%C For example, 99 is in the sequence since its binary form is 1100011 and the composition [2,3,2] has parts: even, odd, even. 100 is not in the sequence since its binary form is 1100100 and the composition [2,2,1,2] has parts even, even, odd, even. The command c(n) from the Maple program yields the composition having index n. (End)

%H Harvey P. Dale, <a href="/A044888/b044888.txt">Table of n, a(n) for n = 1..1000</a>

%p Runs := proc (L) local j, r, i, k: j := 1: r[j] := L[1]: for i from 2 to nops(L) do if L[i] = L[i-1] then r[j] := r[j], L[i] else j := j+1: r[j] := L[i] end if end do: [seq([r[k]], k = 1 .. j)] end proc: RunLengths := proc (L) map(nops, Runs(L)) end proc: c := proc (n) ListTools:-Reverse(convert(n, base, 2)): RunLengths(%) end proc: A := {}: for n to 1540 do if `and`(type(c(n)[1], even) = true, type(product(c(n)[j]-c(n)[j+1], j = 1 .. nops(c(n))-1), odd)) then A := `union`(A, {n}) else end if end do: A; # most of the Maple program is due to _W. Edwin Clark_. # _Emeric Deutsch_, Jan 27 2018

%t oeQ[n_]:=Module[{idsleb=Boole[EvenQ/@(Length/@Split[IntegerDigits[ n,2]])]},idsleb == PadRight[{},Length[idsleb],{1,0}]]; Select[ Range[ 1600],oeQ] (* _Harvey P. Dale_, Sep 04 2020 *)

%o (Python)

%o from itertools import groupby

%o def ok(n): return all(len(list(g))%2 == i%2 for i, (k, g) in enumerate(groupby(bin(n)[2:])))

%o print([i for i in range(1, 1537) if ok(i)]) # _Michael S. Branicky_, Jan 04 2021

%Y Cf. A298644, A101211.

%K nonn,base

%O 1,1

%A _Clark Kimberling_

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 30 04:04 EDT 2024. Contains 372118 sequences. (Running on oeis4.)