Today we'll look at a sequence \$a\$, related to the Collatz function \$f\$:
$$f = \begin{cases} n/2 & \text{if } n \equiv 0 \text{ (mod }2) \\ 3n+1 & \text{if } n \equiv 1 \text{ (mod }2) \\ \end{cases}$$
We call a sequence of the form \$z, f(z), f(f(z)), …\$ a Collatz sequence.
The first number in our sequence, \$a(1)\$, is \$0\$. Under repeated application of \$f\$, it falls into a cycle \$0\to0\to0\to\:\cdots\$
The smallest number we haven't seen yet is 1, making \$a(2)=1\$. Under repeated application of \$f\$, it falls into a cycle \$1\to4\to2\to1\to\cdots\$
Now we have seen the number \$2\$ in the cycle above, so the next smallest number is \$a(3) = 3\$, falling into the cycle \$3\to10\to5\to16\to8\to4\to2\to1\to4\to\cdots\$
In all above cycles we've seen \$4\$ and \$5\$ already, so the next number is \$a(4) = 6\$.
By now you should get the idea. \$a(n)\$ is the smallest number that was not part of any Collatz sequences for all \$a(1), ..., a(n-1)\$
Write a program or function that, given an positive integer \$n\$, returns \$a(n)\$. Shortest code in bytes wins.
Testcases:
1 -> 0
2 -> 1
3 -> 3
4 -> 6
5 -> 7
6 -> 9
7 -> 12
8 -> 15
9 -> 18
10 -> 19
50 -> 114
(This is OEIS sequence A061641.)
n
be 0-based? \$\endgroup\$a(n+1) = a(n) odd: 3*a(n)+1, or a(n) even: a(n)/2
\$\endgroup\$a
isn't 0-based I don't understand why you seem to be "talking 0-based" here:a(n) is the smallest number that was not part of any Collatz sequences for all a(0), …, a(n − 1).
\$\endgroup\$