|
|
A160530
|
|
Positive integers that contain only odd-length runs of 0's and 1's in their binary expansion.
|
|
2
|
|
|
1, 2, 5, 7, 8, 10, 14, 17, 21, 23, 29, 31, 32, 34, 40, 42, 46, 56, 58, 62, 65, 69, 71, 81, 85, 87, 93, 95, 113, 117, 119, 125, 127, 128, 130, 136, 138, 142, 160, 162, 168, 170, 174, 184, 186, 190, 224, 226, 232, 234, 238, 248, 250, 254, 257, 261, 263, 273, 277, 279
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,2
|
|
COMMENTS
|
Let the binary representation of n be thought of as a string of 0's and 1's. By a "run" of 0's or 1's, it is meant either a contiguous substring all of 0's bounded by 1's or the by the edge of the string, or a contiguous substring all of 1's bounded by 0's or the by the edge of the string.
Also, the indices of the compositions that have only odd parts. For the definition of the index of a composition see A298644. For example, 263 is in the sequence since its binary form is 100000111 and the composition [1,5,3] has only odd parts. 132 is not in the sequence since its binary form is 10000100 and the composition [1,4,1,2] also has even parts. The command c(n) from the Maple program yields the composition having index n. - Emeric Deutsch, Jan 26 2018
An even number n is in the sequence if and only if n = 2^k*m where k is odd and m is an odd number in the sequence.
An odd number n is in the sequence if and only if n = 2^k*(m+1)-1 where k is odd and m is 0 or an even number in the sequence. (End)
|
|
LINKS
|
|
|
MAPLE
|
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 280 do if type(product(c(n)[j], j = 1 .. nops(c(n))), odd) = true 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 26 2018
# Alternative:
filter:= proc(n) option remember; local t;
if n::even then
t:= padic:-ordp(n, 2);
if t::even then return false fi;
procname(n/2^t)
else
t:= padic:-ordp(n+1, 2);
if t::even then return false fi;
procname((n+1)/2^t-1)
fi
end proc:
filter(0):= true:
|
|
MATHEMATICA
|
Select[Range[300], And@@OddQ/@Length/@Split[IntegerDigits[ #, 2]]&] (* Ray Chandler, May 19 2009 *)
|
|
PROG
|
(Python)
from itertools import groupby
def ok(n): return all(len(list(g))%2 == 1 for k, g in groupby(bin(n)[2:]))
|
|
CROSSREFS
|
|
|
KEYWORD
|
base,nonn
|
|
AUTHOR
|
|
|
EXTENSIONS
|
|
|
STATUS
|
approved
|
|
|
|