9
Challenge Taken from here and also here
An n parentheses sequence consists of n (s and n )s.
A valid parentheses sequence is defined as the following:
You can find a way to repeat erasing adjacent pair of parentheses "()" until it becomes empty.
For example,
(())is a valid parentheses, you can erase the pair on the 2nd and 3rd position and it becomes(), then you can make it empty.)()(is not a valid parentheses, after you erase the pair on the 2nd and 3rd position, it becomes)(and you cannot erase any more
Task
Given a number n you need to generate all correct parenthesis sequence in lexicographical order
Output can be an array, list or string (in this case a sequence per line)
You can use a different pair of parenthesis such as {}, [], () or any open-close sign
Example
n = 3
((())) (()()) (())() ()(()) ()()()n = 2
(()) ()()
@JoKing Yes of course. I assume that wont make any difference anyway to the main concept of the challenge. – Luis felipe De jesus Munoz – 2018-11-06T14:12:22.420
Eh, I can think of a few languages where eval would interpret them differently for example – Jo King – 2018-11-06T14:13:47.600
1Related: Catalan Numbers (result of that challenge = number of lines of result of this challenge) – user202729 – 2018-11-06T14:23:31.413
3Virtually the same, but with some weird restrictions like "You may not write recursive functions". /// A superset of this challenge (allow all Brain-Flak brackets) – user202729 – 2018-11-06T14:24:20.307
Does "an array, list or string" "of sequences" of "any open-close sign" mean we could output a list of lists of two integers (like
1s and-1s)? – Jonathan Allan – 2018-11-06T19:51:05.613@JonathanAllan You can output a list of list but not using
1, -1. – Luis felipe De jesus Munoz – 2018-11-06T20:29:53.877So what are "any open-close sign"s? Do you mean any pair of open-close characters like
<>,‘’or⁽⁾? – Jonathan Allan – 2018-11-06T20:57:05.713@JonathanAllan Exactly. Sorry if I was unclear on that – Luis felipe De jesus Munoz – 2018-11-06T20:57:52.647