OFFSET
1,2
COMMENTS
Think of binary n as a string S of 0's and 1's. By a "run" of 0's or 1's, it is meant either a substring all of contiguous 0's, each run bounded by 1's or the edge of S; or a substring all of contiguous 1's, each run bounded by 0's or the edge of S.
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..10000
EXAMPLE
451 in binary is 111000011. This contains a run of three 1's, followed by a run of four 0's, followed by a run of two 1's. Since (3,4,2) is a permutation of some number of consecutive positive integers (2,3,4), then 451 is in the sequence.
PROG
(Python)
from itertools import groupby
def ok(n):
runlengths = [len(list(g)) for k, g in groupby(bin(n)[2:])]
minrl = min(runlengths)
return sorted(runlengths) == list(range(minrl, minrl+len(runlengths)))
print([n for n in range(1, 2021) if ok(n)]) # Michael S. Branicky, Jan 04 2021
(Python) # alternate that directly generates terms
from itertools import permutations
def runlengths(k, r): # all terms with runlengths a permutation of k, ..., r
c = ['1', '0']
return sorted([int("".join([c[j%2]*p[j] for j in range(r-k+1)]), 2)
for p in permutations(range(k, r+1))])
def aupto(nn):
digits, k, r, out = 1, 1, 1, []
while len(out) < nn:
for r in range(1, digits + 1):
for k in range(1, r + 1):
if sum(range(k, r+1)) == digits:
out += runlengths(k, r)
digits += 1
return sorted(set(out))[:nn]
print(aupto(56)) # Michael S. Branicky, Jan 04 2021
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Leroy Quet, Jun 01 2009
EXTENSIONS
Extended by Ray Chandler, Jun 13 2009
STATUS
approved