| Bytes | Lang | Time | Link |
|---|---|---|---|
| 240 | Python3 | 250511T214304Z | Ajax1234 |
| 027 | Charcoal | 221021T090134Z | Neil |
| 014 | 05AB1E | 221021T070625Z | Kevin Cr |
| 100 | Python | 221020T235555Z | 97.100.9 |
| 070 | JavaScript ES6 | 221020T190423Z | Arnauld |
| 014 | Jelly | 221020T175624Z | Jonathan |
Python3, 240 bytes
def f(n):
m,q=[n],[0]
for i in q:
o=[]
for I in[-1,1]:
if 0<=(U:=i+I*m[i]):o+=[([0 for _ in range(max(0,U-len(m)+1))],U)]
if(O:=[(a,b)for a,b in o if[]==a])==[]:O=o
M=m;T,U=O[0];m+=T
if m[U]:return M[:-1]
m[U]=m[i]+1;q+=[U]
Charcoal, 27 bytes
Nθ≔Eθ⁺θ⊗ιηI⁺⁺⮌⊞O⊕ηθEθ׳θ✂η¹
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input n.
≔Eθ⁺θ⊗ιη
Create a range from n to 3n-2 in steps of 2.
I⁺⁺⮌⊞O⊕ηθEθ׳θ✂η¹
Increment that range (giving n+1, n+3, ... 3n-1), append n, reverse the result (giving n, 3n-1, 3n-3, ... n+1), append n copies of 3n, then append the range excluding the first element. This outputs n, 3n-1, 3n-3, ... n+1, 3n, ... 3n, n+2, ... 3n-2 as desired.
05AB1E, 14 bytes
4*ŸI·._¦ÂìιнI†
Inspired by @JonathanAllan's Jelly answer.
Try it online or verify all test cases.
Explanation:
# example input: 3
4* # Multiply the (implicit) input by 4
# STACK: 12
Ÿ # Pop and push a list in the range [(implicit) input, 4*input]
# STACK: [3,4,5,6,7,8,9,10,11,12]
I· # Push the input doubled
# STACK: [3,4,5,6,7,8,9,10,11,12],6
._ # Rotate the list that many times towards the left
# STACK: [9,10,11,12,3,4,5,6,7,8]
¦ # Remove the first value
# STACK: [10,11,12,3,4,5,6,7,8]
 # Bifurcate it; shorter for Duplicate & Reverse copy
# STACK: [10,11,12,3,4,5,6,7,8],[8,7,6,5,4,3,12,11,10]
ì # Prepend the second list to the first
# STACK: [8,7,6,5,4,3,12,11,10,10,11,12,3,4,5,6,7,8]
ι # Uninterleave it into two parts
# STACK: [[8,6,4,12,10,11,3,5,7],[7,5,3,11,12,10,4,6,8]]
н # Pop and only leave the first inner list
# STACK: [8,6,4,12,10,11,3,5,7]
I† # Filter the input to the front of the list
# STACK: [3,8,6,4,12,10,11,5,7]
# (after which the result is output implicitly)
Python, 100 bytes
def g(a,n,i):
if len(a)>i>=0:g(a,n+1,i+n);a[i]=n;g(a,n+1,i-n)
def f(n):g(a:=[3*n]*3*n,n,0);print(a)
Uses the same recursive concept as Arnauld's answer.
JavaScript (ES6), 70 bytes
f=(n,i=(a=Array(w=n*3).fill(w),0))=>a[i]?f(n+1,i-n,f(n+1,i+=a[i]=n)):a
Commented
f = ( // f is a recursive function taking:
n, // n = input
i = ( // i = position, initialized to 0
a = Array( // build an array a[]
w = n * 3 // of w = n * 3 entries
).fill(w), // filled with w
0 //
) //
) => //
a[i] ? // if we're not out of bounds:
f( // do a recursive call:
n + 1, // use n + 1 as the value
i - n, // use i - n as the position
f( // do another recursive call:
n + 1, // use n + 1 as the value
i += // use i + n as the position
a[i] = n // and set a[i] to n
) // end of recursive call
) // end of recursive call
: // else:
a // return a[]
Jelly, 15 14 bytes
×3Ṗ+×ɗRṚ;$m2;@
A monadic Link that accepts a positive integer and yields a longest trampoline as a list of positive integers.
How?
Trampolines are \$3n\$ long, start with \$n\$ and are then filled at the leftmost then rightmost available slots starting at \$3n-1\$ descending until \$n\$ slots are left, which need filling with numbers that will go out of bounds in both directions.
i.e. the template is:
[n, 3n-1, 3n-3, ..., <n ?'s>, ..., 3n-4, 3n-2]
The code starts with a list from \$1\$ to \$3n-1\$ and adds \$3ni\$ to the entries at indices \$i\leq n\$ (the ones that will end up at the ?s in the template). It then prefixes this with its reverse, appends the forward version, discards every other element, and prefixes with \$n\$ to give a trampoline.
×3Ṗ+×ɗRṚ;$m2;@ - Link: integer, n e.g. 3
×3 - multiply (n) by three 9
R - range (n) [1,2,3]
ɗ - last three links as a dyad:
Ṗ - pop (3n) [1,2,3,4,5,6,7,8]
× - (3n) multiply (range n) [9,18,27]
+ - add [10,20,30,4,5,6,7,8]
$ - last two links as a monad:
Ṛ - reverse [8,7,6,5,4,30,20,10]
; - concatenate [8,7,6,5,4,30,20,10,10,20,30,4,5,6,7,8]
2 - two
m - modulo slice [8, 6, 4, 20, 10, 30, 5, 7]
@ - with swapped arguments:
; - (n) concatenate [3,8,6,4,20,10,30,5,7]