OFFSET
1,1
COMMENTS
Sequence is a permutation of the positive integers. It is its own inverse permutation.
LINKS
EXAMPLE
Among positive integers not among the first 8 terms of the sequence, 4 (100 in binary) is the smallest positive integer which has the same number of non-leading zeros in its binary representation as 9 (1001 in binary). So a(9) = 4.
PROG
(Python)
from itertools import islice
def val(n): return (~n & n-1).bit_length() # From Chai Wah Wu in A007814
def next0(n):
z = val(n)
f = (n|(2**z)-1) + 1
w = val(f)
if f != 2**w: z+=1
return(f|(2**(w-z)-1))
def a_gen():
B, n = [], 1
while True:
f = 0
for i in B:
if i[0] == n:
f+=1; n+=1; yield(i[1]); B.remove(i); break
if f < 1:
B.append((next0(n), n)); yield(next0(n)); n+=1
A112411_list = list(islice(a_gen(), 100)) # John Tyler Rascoe, Mar 20 2024
CROSSREFS
KEYWORD
base,easy,nonn
AUTHOR
Leroy Quet, Dec 08 2005
EXTENSIONS
More terms from R. J. Mathar, Feb 08 2008
STATUS
approved