OFFSET
1,2
COMMENTS
The concatenated binary expansions of the terms act as instructions to take the next unused odd or even number.
This is a permutation of the positive integers.
LINKS
EXAMPLE
terms 1 3 5 7 2 9
binary {1}, {1, 1}, {1, 0, 1}, {1, 1, 1}, {1, 0}, {1, 0, 0, 1}
terms 1, 3, 5, 7, 2, 9, 11,13,15, 17, 4, 19, 6, 8,21
n = 1 2 3 4 5 6 7 8 9 10 11 ...
a(11) = 4 because the 11th bit in the binary expansions is 0 (from term a(5)=2 as it happens) which means a(11) must be even and 4 is the least even positive integer not yet in the sequence.
MATHEMATICA
a[1]=1; a[n_]:=a[n]=(k=1; While[MemberQ[Array[a, n-1], k]||Boole@OddQ@k!= Flatten[IntegerDigits[Join[Array[a, n-1], {k}], 2]][[n]], k++]; k); Array[a, 73]
PROG
(Python)
from itertools import count, islice
def agen(): # generator of terms
an, parity, nextk = 1, [None, 1, 1, 1], [2, 5]
yield from [1, 3]
for n in count(3):
an = nextk[parity[n]]
yield an
nextk[parity[n]] = nextk[parity[n]] + 2
parity.extend(map(int, bin(an)[2:]))
print(list(islice(agen(), 73))) # Michael S. Branicky, Feb 01 2024
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Giorgos Kalogeropoulos, Feb 01 2024
STATUS
approved