C# - 373 349 339339 335 chars
using C=System.Console;class P{static void Main(string[] z){try{for(dynamic c,p=z[0],a=new int[30000],s=new int[9],f=1>0,i=0,d=0,t=0;;i=(c==51&&f&t=0;;i=c==51&&f&(f|=s[--t]<0))?s[t]:++i){c=p[i]-42;d+=42;a[d+=(c-19)*(f&c>17&c<21?1:0);a[d]+=]+=(2-c)*(f&c>0&c<4?1:0);if(f&c==4)C.Write((char)a[d]);if(f&c==2)a[d]=C.Read();if(c==49)s[t++]=f?(f=a[d]!=0)?i:-1:i;}}catch{}}}
And more readable:
using C=System.Console;
class P
{
static void Main(string[] z)
{
try
{
for(dynamic c,p=z[0],a=new int[30000],s=new int[9],f=1>0,i=0,d=0,t=0;;i=(c==51&&f&t=0;;i=c==51&&f&(f|=s[--t]<0))?s[t]:++i)
{
c=p[i]-42;
d+=a[d+=(c-19)*(f&c>17&c<21?1:0);
a[d]+=]+=(2-c)*(f&c>0&c<4?1:0);
if(f&c==4)C.Write((char)a[d]);
if(f&c==2)a[d]=C.Read();
if(c==49)s[t++]=f?(f=a[d]!=0)?i:-1:i;
}
}
catch{}
}
}
Limitation is it only handles nested [
up to 9 deep. Can make the s
array bigger to handle more.
Edit 373 -> 349: Removed outer loop (was for a different site), character comparisons to integers, moved c
declaration into the for loop
Edit 349 -> 339:
- Combined
+
/-
and>
/<
into single lines. - Reduced integer literal lengths by subtracting 42 from
c
to allow for some of the integer literals to be a single character (credit @ceilingcat). - Moved
i=...
into the for loop iterator section (credit @ceilingcat).
Edit 339 -> 335:
- Combined
+
/-
and>
/<
into a single line (credit @ceilingcat) - Removed unnecessary parenthesis in the
i=...
(credit @ceilingcat)