What is function of this sequence on to natural numbers?

$1,2,4,3,6,5,10,7,14,8,16,9,18,11,22,12,24,13,26,15,30,17,34,19,38,20,40,21,42,23,46,25,50,...$

such that we begin from $1$ and then write $2$ then $2\times2$ then $3$ then $2\times3$ then ... but if $n$ is even and previously we have written $0.5n$ and then $n$ then ignore $n$ and continue and write $n+1$ and then $2n+2$ and so on for example we have $1,2,4,3,6,5,10$ so after $10$ we should write $7,14,...$ because previously we have written $3,6$.

• What did you try and where did you get stuck – tien lee May 13 '18 at 15:30
• @tienlee I need it for Collatz conjecture! – user555988 May 13 '18 at 15:44
• OEISA034701: "a(n) is the smallest number not of the form a(i) (1<=i<=n-1) or a(i)+a(n-1) (1<=i<=n-2)". – r.e.s. May 13 '18 at 15:49
• @r.e.s. thank you! (but it isn't a function) hasn't been defined its function? – user555988 May 13 '18 at 15:59
• In other words, you're asking "How can this sequence be defined without using recursion?" – r.e.s. May 13 '18 at 16:12

Following is a definition of your sequence without using recursion.

Let $S=(S_0,S_1,S_2,\ldots)$ be the increasing sequence of positive integers that are expressible as either $2^e$ or as $o_1\cdot 2^{o_2}$, where $e$ is an even nonnegative integer, $o_1>1$ is an odd positive integer and $o_2$ is an odd positive integer. Thus $$S=(1, 4, 6, 10, 14, 16, 18, 22, 24, 26, 30, 34, 38, 40,42,\ldots).$$ Let $\bar{S}$ be the complement of $S$ with respect to the positive integers; i.e., $$\bar{S}=(2, 3, 5, 7, 8, 9, 11, 12, 13, 15, 17, 19, 20, 21, 23, 25,\ldots).$$ Your sequence is then $T=(T_0,T_1,T_2,\ldots)$, where $$T_n:=\begin{cases}S_{n\over 2}&\text{ if n is even}\\ \bar{S}_{n-1\over 2}&\text{ if n is odd.} \end{cases}$$ Thus $T=(1, 2, 4, 3, 6, 5, 10, 7, 14, 8, 16, 9, 18, 11, 22, 12, 24, 13, 26, 15, 30, 17, 34, 19, 38, 20, \ldots).$

References:

Sequences $S,\bar{S},T$ are OEIS A171945, A053661, A034701 respectively. These are all discussed in "The vile, dopey, evil and odious game players".

Sage code:

def is_in_S(n): return ( (n.valuation(2) % 2 == 0) and (n.is_power_of(2))  ) or ( (n.valuation(2) % 2 == 1) and not(n.is_power_of(2))  )
S = [n for n in [1..50] if is_in_S(n)]
S_ = [n for n in [1..50] if not is_in_S(n)]
T = []
for i in range(max(len(S),len(S_))):
if i % 2 == 0: T += [S[i/2]]
else: T += [S_[(i-1)/2]]
print S
print S_
print T

[1, 4, 6, 10, 14, 16, 18, 22, 24, 26, 30, 34, 38, 40, 42, 46, 50]
[2, 3, 5, 7, 8, 9, 11, 12, 13, 15, 17, 19, 20, 21, 23, 25, 27, 28, 29, 31, 32, 33, 35, 36, 37, 39, 41, 43, 44, 45, 47, 48, 49]
[1, 2, 4, 3, 6, 5, 10, 7, 14, 8, 16, 9, 18, 11, 22, 12, 24, 13, 26, 15, 30, 17, 34, 19, 38, 20, 40, 21, 42, 23, 46, 25, 50]

• Thank you so much! you are great! – user555988 May 14 '18 at 21:01