Skip to main content
added 1276 characters in body
Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

CJam, 21 bytes

qe#ere$_"}{][><)("%Wq

[Test it here.][1]

Normal reversion:

qW%"()<>[]{}"_$ere#eq

[Test it here.][2]

Visual reversion:

qW%")(><][}{"_$ere#eq

[Test it here.][3]

Explanation

First, the normal code:

qe#ere$_"}{][><)("%Wq

This is simple: q reads all input, e# comments out the remainder of the program, and the input is printed implicitly at the end.

Now the normal reversion:

q            e# Read all input.
W%           e# Reverse it.
"()<>[]{}"   e# Push this string.
_$           e# Duplicate and sort it. However, the string is already sorted
             e# so we just get two copies of it.
er           e# Transliteration (i.e. character-wise substitution). But since the
             e# source and target string are identical, the reversed input
             e# is left unchanged.
e#eq            Just a comment...

And finally, the visual reversion:

q            e# Read all input.
W%           e# Reverse it.
")(><][}{"   e# Push this string.
_$           e# Duplicate and sort it. This gives us "()<>[]{}", i.e. the
             e# same string with each bracket pair swapped.
er           e# Transliteration (i.e. character-wise substitution). This
             e# time, this toggles all the brackets in the reversed input
             e# completing the visual reversion.
e#eq            Just a comment...

[1]: http://cjam.aditsu.net/#code=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq&input=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq [2]: http://cjam.aditsu.net/#code=qW%25%22()%3C%3E%5B%5D%7B%7D%22_%24ere%23eq&input=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq [3]: http://cjam.aditsu.net/#code=qW%25%22)(%3E%3C%5D%5B%7D%7B%22_%24ere%23eq&input=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq

CJam, 21 bytes

qe#ere$_"}{][><)("%Wq

[Test it here.][1]

Normal reversion:

qW%"()<>[]{}"_$ere#eq

[Test it here.][2]

Visual reversion:

qW%")(><][}{"_$ere#eq

[Test it here.][3]

[1]: http://cjam.aditsu.net/#code=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq&input=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq [2]: http://cjam.aditsu.net/#code=qW%25%22()%3C%3E%5B%5D%7B%7D%22_%24ere%23eq&input=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq [3]: http://cjam.aditsu.net/#code=qW%25%22)(%3E%3C%5D%5B%7D%7B%22_%24ere%23eq&input=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq

CJam, 21 bytes

qe#ere$_"}{][><)("%Wq

[Test it here.][1]

Normal reversion:

qW%"()<>[]{}"_$ere#eq

[Test it here.][2]

Visual reversion:

qW%")(><][}{"_$ere#eq

[Test it here.][3]

Explanation

First, the normal code:

qe#ere$_"}{][><)("%Wq

This is simple: q reads all input, e# comments out the remainder of the program, and the input is printed implicitly at the end.

Now the normal reversion:

q            e# Read all input.
W%           e# Reverse it.
"()<>[]{}"   e# Push this string.
_$           e# Duplicate and sort it. However, the string is already sorted
             e# so we just get two copies of it.
er           e# Transliteration (i.e. character-wise substitution). But since the
             e# source and target string are identical, the reversed input
             e# is left unchanged.
e#eq            Just a comment...

And finally, the visual reversion:

q            e# Read all input.
W%           e# Reverse it.
")(><][}{"   e# Push this string.
_$           e# Duplicate and sort it. This gives us "()<>[]{}", i.e. the
             e# same string with each bracket pair swapped.
er           e# Transliteration (i.e. character-wise substitution). This
             e# time, this toggles all the brackets in the reversed input
             e# completing the visual reversion.
e#eq            Just a comment...

[1]: http://cjam.aditsu.net/#code=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq&input=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq [2]: http://cjam.aditsu.net/#code=qW%25%22()%3C%3E%5B%5D%7B%7D%22_%24ere%23eq&input=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq [3]: http://cjam.aditsu.net/#code=qW%25%22)(%3E%3C%5D%5B%7D%7B%22_%24ere%23eq&input=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq

Source Link
Martin Ender
  • 197.2k
  • 67
  • 447
  • 975

CJam, 21 bytes

qe#ere$_"}{][><)("%Wq

[Test it here.][1]

Normal reversion:

qW%"()<>[]{}"_$ere#eq

[Test it here.][2]

Visual reversion:

qW%")(><][}{"_$ere#eq

[Test it here.][3]

[1]: http://cjam.aditsu.net/#code=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq&input=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq [2]: http://cjam.aditsu.net/#code=qW%25%22()%3C%3E%5B%5D%7B%7D%22_%24ere%23eq&input=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq [3]: http://cjam.aditsu.net/#code=qW%25%22)(%3E%3C%5D%5B%7D%7B%22_%24ere%23eq&input=qe%23ere%24_%22%7D%7B%5D%5B%3E%3C)(%22%25Wq