9
Based on THIS question.
Given a string, replace each bracket ()[]{}<> with a bracket of the appropriate type so that the brackets match, and the nested brackets cycle as follows:
- Outermost ones are
() - Directly inside of
()should be[] - Directly inside of
[]should be{} - Directly inside of
{}should be<> - Directly inside of
<>will be()again (cycles)
All non-bracket chars must remain exactly as they are. Open brackets may only be replaced with open brackets of some type, and close brackets with close brackets.
The input will always make this possible. This means its brackets matched correctly if their type is ignored. So, {ab<)c] is a valid input, but ab)(cd or ab((cd are not.
Examples:
2#jd {¤>. = 2#jd (¤).
abcdef = abcdef
(3×5+(4-1)) = (3×5+[4-1])
<<<>><<>><<<<<<>>>>>>> = ([{}][{}][{<([{}])>}])
The use of native transforming of input this way (auto syntax of language) is not allowed.
As always: shortest code wins.
I don't understand the challenge. What must the output be in terms of the input? – xnor – 2016-12-11T05:39:44.520
@xnor the output should be the same string like the input, except for the four kinds of brackets. They need to be replaced to match the pattern. – Dirk Reichel – 2016-12-11T05:49:02.810
Ah, now I see. I didn't understand that the "should be" are things you're supposed to make be true. I'll edit to try to make it clearer. – xnor – 2016-12-11T05:50:38.397
I edited the specs. Feel free to change things if I messed them up. I'm not sure what "native transforming of input" means, so I left it alone. – xnor – 2016-12-11T05:59:45.957
@xnor I wasn't sure how to put it, but there may be languages which will transform brackets just by the compiler in some way. And I don't want a use of something like that... – Dirk Reichel – 2016-12-11T06:18:43.660
1@DirkReichel I don't think that is something you need to worry about. I can't imagine that any language can do this specific transformation natively, and in the unlikely event that there is such a language all that means is that answers in that language won't be very interesting. – Martin Ender – 2016-12-11T10:08:08.087
What characters can appear in the input? I see you've got some non-ASCII there. – Martin Ender – 2016-12-11T10:09:13.240
@MartinEnder in theory: all printable unicode symbols. – Dirk Reichel – 2016-12-11T12:39:13.193
2@DirkReichel what's the point? Just stick with ASCII. Using different characters adds nothing to the challenge apart from unnecessary restrictions on ascii-only languages. – FlipTack – 2016-12-11T13:19:22.090
@Flp.Tkc there is no "need to run with unicode". If your language is ascii-only, only ascii inputs need to run. I assumed something like that as completely "off topic" for this task. – Dirk Reichel – 2016-12-11T18:04:01.627