Convert Chevrons to Soliduses
CJam, 35 bytes
qN/_s,S*f+{iD%[S3*" \/"_$]=}f%W%zN*
Try it online here
CJam, 37 bytes
qN/_z,S*f{+"< >""/\ \/ "3/er}W%zN*
Try it online in the CJam interpreter.
How it works
qN/ e# Read from STDIN and split at linefeeds.
_z, e# Zip a copy and push the results length.
e# This computes the maximum line length.
S* e# Repeat " " that many times.
f{ } e# For each line:
e# Push the string of spaces.
+ e# Append it to the line.
"< >""/\ \/ "3/ e# Push "< >" and ["/\ " " " "\/ "].
er e# Perform transliteration.
W%z e# Reverse the lines and zip.
e# This rotates by 90 degrees.
N* e# Join, separating by linefeeds.
Python 2, 105 bytes
def f(s):
for row in map(None,*s.split("\n")):print" ".join("\/ /\ "[1-cmp(c,"<")::3]for c in row[::-1])
For all the wrong reasons, this has got to be one of the nicest uses of map(None, ...)
I've had so far. The output even pads to perfect rectangle.
Let's take the second example:
><<<>
<><
map(None,*s.split("\n"))
performs a poor man's zip_longest
, giving:
[('>', ' '), ('<', '<'), ('<', '>'), ('<', '<'), ('>', None)]
Notice how the second line is shorter than the first, so we get a None
at the end. Normally this would be a problem, but for some reason almost everything is comparable in Python 2, and in particular
>>> None < ""
True
This means that the expression 1-cmp(c,"<")
returns 0, 1, 2
for ">", "<", None
respectively, allowing us to use the string slicing trick to extract one of "\/", "/\", " "
. Using this, we print the output line by line, joining the 2-char groups with spaces.