2 ms·
Yes, you are both quite correct (I was thinking along the lines mentioned by Twisol). I was looking at the basic approach as a walk in 1D. In the students repr
by Anon84 8y ago
Yes, you are both quite correct (I was thinking along the lines mentioned by Twisol).
I was looking at the basic approach as a walk in 1D. In the students representation, this means that each tuple is ordered, implying a move forward (you start with a "(" and eventually end at a ")". As a walk, this means that you return to the origin without ever becoming negative.
In my rush, I generalized too quickly for the case of the two brackets as just a similar random walk in 2D. This of course doesn't work in the example you mentioned. If () corresponds to the xx dimension and {} to the yy axis:
- With "({)}" you do return to the origin [[1, 0], [1,1], [0, 1], [0, 0]] but not in a valid path.
- You basically need one extra rule. At each step, you can move forward in any direction (open a new type of bracket), but you can only move back in the direction you just came from (close the previous one).
This of course is just a weird way of representing a stack, because you still need to keep track of the entire history anyway (which you could just store as the brackets themselves.
To paraphrase one of my idols, "More (dimensions) is different"...