| Bytes | Lang | Time | Link |
|---|---|---|---|
| 088 | Setanta | 240725T051345Z | bb94 |
| 023 | Uiua | 240724T165636Z | nyxbird |
| 013 | JCram | 240724T134902Z | Kamila S |
| 010 | Vyxal | 211225T121254Z | lyxal |
| 272 | Turing Machine Code | 150921T002151Z | SuperJed |
| 011 | Stax | 180409T134224Z | Weijun Z |
| 159 | Haskell | 140103T221059Z | jgon |
| 025 | Pyth | 180409T191016Z | hakr14 |
| 104 | Hassium | 150920T011442Z | Jacob Mi |
| 5958 | Ruby | 140103T212626Z | daniero |
Setanta, 88 bytes
gniomh(s){a:=0le i idir(0,fad@s){i=s[i]a+=(i=='['|0&1)-(i==']'|0&1)ma a<0 bris}toradh!a}
JCram, 13 bytes.
5,⍥ψ⍺⍘ⒼιV⍣b⍐B
Encodes the ES6 program
f=s=>(t=s.replace(/\[\]|[^\[\]]/g,''))==s?!s:f(t)
Vyxal, 10 bytes
‛[]↔øβ¬[°*
The joys of having a balanced-bracket digraph.
Explained
‛[]↔øβ¬[°*
‛[]↔ # remove all non "[]" from the input
øβ¬ # are the brackets unbalanced?
[°* # if so, multiply the input by the imaginary number `i`. Obviously you can't multiply a string by an imaginary number in python, so this errors.
Turing Machine Code, 286 272 bytes
Again, I'm using the rule table syntax defined here.
0 * * l 1
1 _ ! r Q
5 _ _ r 5
5 * * * W
W [ ! l E
W ] ! l T
W _ _ l I
W * ! r *
E ! ! l *
E * * * R
R _ [ r O
R * * l *
T ! ! l *
T * * * Y
Y _ _ r U
Y * * l *
U [ _ r O
U ! ! * halt-r
I ! ! l *
I _ _ r halt
I * * l halt-r
O ! ! r Q
O _ _ l I
O * * r *
Q ! ! r *
Q * * * W
Terminates in state halt to accept the input and halt-r to reject it.
Stax, 14 11 characters
╬Äτ↔EªÉs «Ü
Credit to @recursive for -3 bytes.
ASCII equivalent:
.[]Y|&{yz|egp!
Remove all characters except [], then remove [] until the string no longer changes. Return 1 if the final string is empty.
Haskell (167,159)
Did this mostly for fun, if anyone's got any suggestions for how to make it shorter, I'd be glad to hear them tho :)
import System.Exit
p x y b|b=x|True=y
main=getContents>>=(return.all (>=0).scanl (\v->p (v-1) (v+1).(==']')) 0.filter (`elem`"[]"))>>=p exitSuccess exitFailure
Edit: Fixed an issue pointed out to me in the comments (added 11 bytes).
Edit 2: Created auxiliary function for testing predicates using guards inspired by user13350, removing 8 bytes.
Pyth, 25 bytes
Ilzv::z"[^[\]]"k"]\[""],[
Python 3 translation:
import re
z=input()
if len(z):
print(eval(re.sub("]\[","],[",re.sub("[^[\]]","",z))))
Hassium, 104 Bytes
func main(){l=0;r=0;b=input();foreach (c in b){if(c=="[")l++;if(c=="]")r++;}if(!(r==l))exit(1);exit(0);}
Full expanded (note doesn't work in online interpreter as input() is disabled) here
Ruby, 59 58
Scans for opening and closing bracket, counting [ as 1 and ] as -1, and exits if the count drops below 0.
b=0
$<.read.scan(/\]|\[/){exit 1if(b+=92-$&.ord)<0}
exit b