We’re rewarding the question askers & reputations are being recalculated! Read more.

New answers tagged

1

Brain-Flak, 302 bytes {(({}(<()>))<({}[(((()()()()()){}){}){}])>{[()](<()>)}{}<({}[()])>{()(<()>)}{}<({}[(((()()())){}{}){}()])>{[()()](<()>)}{}<({}[()()])>{()()(<()>)}{}<({}[(((()()()){}()){}){}()])>{[()()](<()>)}{}<({}[()()])>{()()(<()>)}{}<({}[(((()()()()()){})){}{}])>{[()...


4

Canvas, 1 byte ↔ Try it here! Surprised that this is the first 1-byte answer.


0

C (gcc), 85 84 64 60 bytes 60 bytes thanks to Neil p;f(char*s){for(p=strlen(s);p--;)putchar(s[p]^68%s[p]/3%8);} Try it online!


2

Japt, 12 bytes Blatant port of Arnauld's JS solution so go upvote him. ÔcÈ^68%X/3%8 Try it


1

Jelly, 13 bytes This approach has many 13-byte solutions, although I can golf Arnauld's 13 byter to 12 bytes. QṢiⱮịQṢṭ2/FƲṚ Try it online! How? QṢiⱮịQṢṭ2/FƲṚ - Link: list of characters, P Q - de-duplicate (P) Ṣ - sort (call this X) Ɱ - map across (p in) P with: i - first index of (p) in (X) Ʋ ...


0

Perl 5 -p, 32 bytes $_=reverse y/(){}[]<>/)(}{][></r Try it online!


6

Jelly,  13  12 bytes Saved 1 byte thanks to @JonathanAllan O&80%15‘^OỌṚ Try it online! How? The idea here is to XOR the ASCII codes to turn each character into its mirrored counterpart, like I did in my JS answer. But we use a formula that is bit golfier in Jelly: $$f(c)=((c\text{ & }80)\bmod 15)+1$$ where \$\text{&}\$ is a ...


0

Jelly, 15 bytes “[({})]”©iⱮUịUɼ Try it online! A monadic link that reverses the input and input brackets of all their types.


6

Python 3, 47 bytes lambda x:x[::-1].translate('>]<[)('*20+'}_{'*2) Try it online! Python has a convenient string method translate that accepts a translation string s, and maps each character c to s[ord(c)]. So, we just need to make a translation string with the right characters at the positions of ASCII values [40, 41, 60, 62, 91, 93, 123, 125] of ()...


4

J, 24 bytes |.rplc(;"0|.)@'([{<>}])' Try it online! Test cases by Jonah.


0

Red, 56 bytes func[s][foreach c reverse s[prin select"[][()({}{<><"c]] Try it online!


1

Icon, 67 bytes procedure f(s) r:="reverse" return map(r(s),d:="([{<>}])",r(d)) end Try it online!


2

Retina 0.8.2, 20 bytes O^$`. T`([{<>}])`Ro Try it online! Link includes test cases. Explanation: O`. Sort individual characters... $ ... by substitution value (constant empty string, therefore keeps original order)... ^ ... with reversed sort order (i.e. reversing the string). T`([{<>}]) Substitute each character of ([{<>}])... `...


2

J, 32 25 bytes '([{<)]}>'|.@([{~8|4+i.)] Try it online! Quick explanation: Find the index of each input char within the string '([{<)]}>'. Add 4 to it to get its mirror Take that mod 8 to handle wrapping around to the beginning Use the result to index back into '([{<)]}>' And reverse that result


9

Charcoal, 3 bytes S‖T Try it online! Link is to verbose version of code. Explanation: S reads the input and implicitly echos it, while ‖ is the mirroring operator, which normally just reverses the input, but the T modifies it to mirror the characters at the same time.


7

JavaScript (Node.js),  51 47  44 bytes Saved 3 bytes thanks to @xnor s=>Buffer(s).map(c=>c^68%c/3%8).reverse()+'' Try it online! How? For each pair of characters, we can switch from the 1st to the 2nd character (and vice versa) by XOR'ing the ASCII code with \$1\$, \$2\$ or \$6\$. char 1 | code | XOR | code | char 2 --------+------+----...


4

05AB1E, 4 bytes º2äθ Try it online! or verify all test cases Explanation º | Mirror (i.e. "({}[{}])" -> "({}[{}])([{}]{})" 2ä | Split into two pieces θ | Take the last piece


1

Python 3, 61 bytes lambda x,s="([<{}>])":"".join(s[7-s.find(c)]for c in x[::-1]) Try it online!


Top 50 recent answers are included