67
votes
42
votes
r flag my Vyxal
05AB1E, 15 12 10 9 bytes
-1 byte thanks to Kevin Cruijssen!
This could be 8 bytes without the l, but why would I remove that?
...
25
votes
19
votes
Implementing a stack
MATL, 6 bytes
"@?@}x
Input is a row vector of numbers.
The final stack is shown upside down, with the most recent element below.
Try it online! Or verify all ...
16
votes
16
votes
13
votes
Implementing a stack
Java (JDK 10), 42 bytes
Since "[the] output is flexible [...], the only thing that matters is the order", this changes the input array into a 0-terminated array. ...
13
votes
13
votes
Implement a simple stack language
Regex (PCRE 2), 104 bytes (60 + 46)
+2 bytes to properly remove excess spaces after ~ commands
Search:
...
12
votes
Implementing a stack
PowerShell, 46 41 40 bytes
$args|%{$x,$a=&({1,$_+$a},{$a})[!$_]};$a
Try it online!
Takes input via splatting, e.g., ...
12
votes
Implementing a stack
Sed, 17 Bytes
:;s/[0-9]\+,0//;t
-3 bytes thanks to @OMᗺ, -1 thanks to @eggyal
Because you're guaranteed to never pop an empty list, you don't need anything more ...
12
votes
r flag my Vyxal
Vyxal, 18 12 8 bytes
(n:Ǎ[∇pp
Try it Online!
-5 thanks to @AUsername
and -1 to an extra golf on that golf
but then another -4 from A Username
The irony here is ...
11
votes
Implementing a stack
C (gcc), 62 60 56 55 bytes
-2 -6 bytes thanks to l4m2
-1 byte thanks to ceilingcat.
Uses the permitted notion of -1 terminated arrays. f() calls itself ...
11
votes
10
votes
Implementing a stack
R, 45 bytes
o={};for(e in scan())o="if"(e,c(e,o),o[-1]);o
Try it online!
-4 byte thanks to @Giuseppe
10
votes
10
votes
10
votes
Implement a simple stack language
JavaScript (Node.js), 103 bytes
-2bytes by l4m2
p=>p.split` `.reduce(([a=[],b=[],...S],i)=>[{A:a+b,S:b-a,X:[b,a],P:b}[i]??[1/i?+i:a,a,b],S].flat(2),[])
...
9
votes
Solve a Stack State Diagram
Python 3, 84 bytes
lambda n,*s:"DLL"+"L".join(i*"SLSC"+"LSLSCDURLCULCULSC"for i in s[::-1])+n*"SR"+"UR"
Usage:
...
9
votes
Make an interpreter for yes!
JavaScript (ES6), 218 215 204 203 bytes
Takes the program string s and the input i in currying syntax ...
9
votes
Implementing a stack
Brain-Flak, 40 36 bytes
([]){{}{({}<>)<>}([]){{}<>}{}([])}<>
Try it online!
Thanks to @Nitrodon for -4 bytes.
Since Brain-Flak already ...
9
votes
Implementing a stack
Python 2, 59 57 51 bytes
s=[]
for x in input():s=(s+[x],s[:-1])[x<1]
print s
Try it online!
9
votes
Implementing a stack
Wolfram Language (Mathematica), 28 bytes
#//.{a___,b_,0,c___}:>{a,c}&
Try it online!
9
votes
Implementing a stack
Python 2, 48 bytes
s=[]
for x in input():s=([x]+s)[2*0**x:]
print s
Try it online!
9
votes
r flag my Vyxal
K (ngn/k), 34 33 bytes
{$[y<58;x,y;(-2_x),,(,/2#|x),y]}/
Try it online!
A single neat K scan.
Returns a singleton list with the output.
-1 byte from Traws.
...
9
votes
Could you massage this stack for me?
K (ngn/k), 42 bytes
{,//a,({(x#2;|!3;x#,3 0)}'x?y),2+a,2+a:~x}
Try it online!
Verify the test cases!
Takes the input as two lists of positive integers (or chars). ...
8
votes
Golf a Brain-Flak Integer
Lua 5.3, 57522
I actually started working on this back when the question was posted, but forgot about it until the Brain-Flak anniversary.
...
8
votes
8
votes
This is how we roll
Haskell, 64 62 bytes
Edit: -2 bytes: @xnor saw something I'd thought wrong about.
r takes and returns a list of Ints.
...
8
votes
This is how we roll
JavaScript (ES6), 49 47 bytes
(t,d,...a)=>a.splice(t=(t%d+d)%d,d-t).concat(a)
Edit: Saved 2 bytes thanks to @Shaggy by taking the stack elements as separate ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
stack × 44code-golf × 29
interpreter × 12
code-challenge × 8
number × 5
metagolf × 5
sequence × 4
game × 4
sorting × 4
optimization × 4
befunge × 3
string × 2
math × 2
popularity-contest × 2
code-generation × 2
data-structures × 2
brain-flak × 2
ascii-art × 1
kolmogorov-complexity × 1
arithmetic × 1
geometry × 1
graphical-output × 1
parsing × 1
image-processing × 1
path-finding × 1