Skip to main content
Improvement by ceilingcat
Source Link
Fhuvi
  • 1.8k
  • 1
  • 7
  • 17

Java (JDK), 110107 110 122 bytes

-12 bytes after the added possibility to output the list as a string joined with linebreaks
-3 bytes thanks to ceilingcat

Port of my JS answer, see explanations here

s->{var r="";int a=0;for(var c:s.toCharArray())r+=c==','&r+=c==44&(a+=("{[()]}".indexOf(c)+4)%7-3)==0?"\n"10:c;return r;}

Try it online!Try it online!

Java (JDK), 110 122 bytes

-12 bytes after the added possibility to output the list as a string joined with linebreaks

Port of my JS answer, see explanations here

s->{var r="";int a=0;for(var c:s.toCharArray())r+=c==','&(a+=("{[()]}".indexOf(c)+4)%7-3)==0?"\n":c;return r;}

Try it online!

Java (JDK), 107 110 122 bytes

-12 bytes after the added possibility to output the list as a string joined with linebreaks
-3 bytes thanks to ceilingcat

Port of my JS answer, see explanations here

s->{var r="";int a=0;for(var c:s.toCharArray())r+=c==44&(a+=("{[()]}".indexOf(c)+4)%7-3)==0?10:c;return r;}

Try it online!

Improved solution
Source Link
Fhuvi
  • 1.8k
  • 1
  • 7
  • 17

Java (JDK), 122110 122 bytes

-12 bytes after the added possibility to output the list as a string joined with linebreaks

Port of my JS answer, see explanations here.

s->{var r="";int a=0;for(var c:s.toCharArray())r+=c==','&(a+=("{[()]}".indexOf(c)+4)%7-3)==0?",,""\n":c;return r.split(",,");r;}

Try it online!Try it online!

Java (JDK), 122 bytes

Port of my JS answer, see explanations here.

s->{var r="";int a=0;for(var c:s.toCharArray())r+=c==','&(a+=("{[()]}".indexOf(c)+4)%7-3)==0?",,":c;return r.split(",,");}

Try it online!

Java (JDK), 110 122 bytes

-12 bytes after the added possibility to output the list as a string joined with linebreaks

Port of my JS answer, see explanations here

s->{var r="";int a=0;for(var c:s.toCharArray())r+=c==','&(a+=("{[()]}".indexOf(c)+4)%7-3)==0?"\n":c;return r;}

Try it online!

Source Link
Fhuvi
  • 1.8k
  • 1
  • 7
  • 17

Java (JDK), 122 bytes

Port of my JS answer, see explanations here.

s->{var r="";int a=0;for(var c:s.toCharArray())r+=c==','&(a+=("{[()]}".indexOf(c)+4)%7-3)==0?",,":c;return r.split(",,");}

Try it online!