| Bytes | Lang | Time | Link |
|---|---|---|---|
| nan | 240803T215928Z | Швеев Ал | |
| 014 | 240723T213211Z | noodle p | |
| 017 | 17 bytes | 240724T095917Z | Bubbler |
| 019 | 240723T163728Z | Styleurc | |
| 024 | 24 bytes | 240723T153830Z | ovs |
just because why not
Stack Control, 9 characters, 25 bytes
⟧⇆#←⟲⟦⇆←⦽
try:
"a" "b" "c" "d" "e" "f" 4 ⟧⇆#←⟲⟦⇆←⦽
Explanation:
Ⅰ - stack cursor
⟧ - place reverse list generator closer
(stack: a b c d e f 4 ⟧Ⅰ)
⇆ - swap 2 last elements
(stack: a b c d e f ⟧ 4Ⅰ)
# - place next function on stack (instead of executing it)
← - function "move cursor left"
(stack: a b c d e f ⟧ 4 #←Ⅰ)
⟲ - repeat ← function 4 times (last values "4 #←" was popped)
(stack: a bⅠ c d e f ⟧)
⟦ - generate list to the next reverse closing bracket
(stack: a b [c d e f]Ⅰ)
⇆ - swap 2 last elements
(stack: a [c d e f] bⅠ)
← - move cursor left
(stack: a [c d e f]Ⅰ b)
⦽ - unpack array
(stack: a c d e fⅠ b)
(optionaly) → - move cursor right
(stack: a c d e f bⅠ)
16 15 14 bytes
~]:a)<~a)>{\}*
Based on ovs's solution, but instead of separating N from the stack and assigning each to a variable, I do the ~ before collecting the stack into an array, and just use this array with ). Then the first part of the stack is dumped, and the second part is dumped by doing {\}* (reduce by swapping) which was jimmy23013's great idea to dump while moving the front of the array to the back.
ovs had a suggestion that reduced this from 16 to 15 bytes by eliminating the variable a. However jimmy23013 later suggested to add that variable a back in and rather eliminate the variable x, which is even shorter! Thanks to both for their suggestions.
17 bytes
(:x{[\]}*{~@@}x*\
An entirely different approach that does not involve wrapping entire stack. Given n, the two top values are wrapped n-1 times, putting the item to be brought up at the 2nd top position. Then the nested pairs are unwrapped, keeping the target at the 2nd top position, and finally it gets swapped to the top.
22 19 bytes
])~1$1$<@@>[(](\++~
explanation:
]) # Separate the stack and the argument
~ # NOT the argument
1$1$ # Duplicate the stack and argument so there are two of each, alternating
< # Objects under the index
@@> # Objects at or above the index
[(](\ # Move the object at the index to the top, in a list
++~ # Concatenate and unpack everything
24 bytes
there is still plenty of room to golf this further, but I think this version shows the idea well.
:k;]:s;s k~<s k~>(:x;+~x
with some comments:
:k;]:s; # inputs: number k, rest of stack s
s k~< # stack without top k+1 values
s k~> # top k+1 values
(:x; # the value to be rotated to the front
+~x # push everything to the stack