New order #4: World
JavaScript (ES6), 55 51 50 bytes
Saved 1 byte thanks to @EmbodimentofIgnorance
Saved 1 byte thanks to @tsh
n=>eval("for(o=[p=2];n--;)o[p=o[q=p>>1]?3*p:q]=p")
Try it online!
Jelly, 15 bytes
µ×3żHḞḢḟȯ1Ṫ;µ¡Ḣ
A full program accepting the integer, n
(1-based), from STDIN which prints the result.
Try it online!
How?
µ×3żHḞḢḟȯ1Ṫ;µ¡Ḣ - Main Link: no arguments (implicit left argument = 0)
µ µ¡ - repeat this monadic chain STDIN times (starting with x=0)
- e.g. x = ... 0 [1,0] [9,3,1,0]
×3 - multiply by 3 0 [3,0] [27,9,3,0]
H - halve 0 [1.5,0] [4.5,1.5,0.5,0]
ż - zip together [0,0] [[3,1.5],[0,0]] [[27,4.5],[9,1.5],[3,0.5],[0,0]]
Ḟ - floor [0,0] [[3,1],[0,0]] [[27,4],[9,1],[3,0],[0,0]]
Ḣ - head 0 [3,1] [27,4]
ḟ - filter discard if in x [] [3] [27,4]
ȯ1 - logical OR with 1 1 [3] [27,4]
Ṫ - tail 1 3 4
; - concatenate with x [1,0] [3,1,0] [4,9,3,1,0]
Ḣ - head 1 3 4
- implicit print
Perl 6, 49 bytes
-2 bytes thanks to nwellnof
{(1,3,{(3*@_[*-1]Xdiv 6,1).max(*∉@_)}...*)[$_]}
Try it online!
Returns the 0-indexed element in the sequence. You can change this to 1-indexed by changing the starting elements to 0,1
instead of 1,3
Explanation:
{ } # Anonymous code block
( ...*)[$_] # Index into the infinite sequence
1,3 # That starts with 1,3
,{ } # And each element is
( ).max( ) # The first of
@_[*-1]X # The previous element
3* div 6 # Halved and floored
3* div ,1 # Or tripled
*∉@_ # That hasn't appeared in the sequence yet