Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
If you're happy to use a default alias (%) you can knock a few bytes off the pwsh: ($p="($args)")-split''|%{$p=$p-replace'\((\(((\()|[^)]|(?<-3>.))*\))\)','$1'};$p-replace'^.|.$'
@tsh yes, this script generates examples where you have to visit one node at least length/2+1 times: gist.github.com/VisualMelon/50ad520ad47ad58be8cd1e4ba0e36bb9 - code has additional notes, but basically it builds a binary tree where the leaves take you back to the root of the binary tree: this means you have to traverse the tree as many times as there are leaves (and there are length/2+1 leaves).
@Veskah yeah, but it assumes that $i is left uninitialized, or initialised to 0 explicitly, and I'd personally rather not make that assumption ;) (if you run the script twice from the same session, it will produce incorrect results)
You can trade the quoted addition for raw text: ' '*($n+1)+"|" -> ' '*$n+" |"? Also, I think you can shave quite a handful of bytes by switching to inlined expressions in some of the strings, e.g. ($x=''+'-'*++$i+'')` -> ($x="*$('-'*++$i)*") ($(stuff) is cheaper than the "+stuff+"). Inlining the extra '-' there also means you can use $i instead of 2*$n, and --$i instead of ($i-2) later on. You can also assign $x in the loop to save 2 bytes.
I can't seem to get this to run correctly (ValueError: not enough values to unpack (expected 3, got 1), python 3.6.6); can you provide a TIO link or some description on how to run it. I think it might be bending the rules by assuming the input is all on one line, but I wasn't entirely clear about that in the question so I won't complain.
Last couple of hints (I should be asleep...) 8. Changing to s+="\n\n" and removing s="" gives you one of the outputs straight away: you just have to find a way to terminate the loop sooner (left as an exercise). 9. You can save a few bytes by re-computing m every time: added over-head of m=1, but removes the ternary (so you can use m*=2) and means you can remove j completely (replace 1<<j++ with m). Should get you down to 159. (I'm a C#er, I would never post a Java answer! and anyway, nothing I've done is original; it's just golfing your method)
@Marco13 indeed, they are classic tricks, but all applicable here specifically. I won't spoil the fun by giving you my 172 byte solution based on them (BTW, it think yours is 192, not 191, but I don't know how the lambda counting works: I'm opposed to it in any case).