| Bytes | Lang | Time | Link |
|---|---|---|---|
| 099 | Perl 5 lF | 241107T214741Z | Xcali |
| 015 | Vyxal | 210618T101846Z | emanresu |
| 019 | Jelly | 210620T103206Z | Unrelate |
| 019 | Stax | 210620T100233Z | Razetime |
| 030 | Husk | 201010T094953Z | Razetime |
| 119 | Perl | 150718T230143Z | faubi |
| 180 | Scala | 150717T124056Z | gilad ho |
| 035 | CJam | 150717T104523Z | Optimize |
| 105 | Python 2 | 150717T073924Z | Sp3000 |
| 037 | CJam | 150716T235909Z | Dennis |
Perl 5 -lF, 99 bytes
push@;,[@F]}{map{//;say map$$_[$']eq'<'?'/\\ ':$$_[$']eq'>'?'\\/ ':' ',reverse@;}0..max map$#$_,@
Vyxal, 15 bytes
øṀð+Ṙ∩øɽ⁋‛<>k/Ŀ
øṀ # Mirror each char vertically - "<" -> "<>", ">" -> "><", " " -> " "
ð+ # Append a space to each
Ṙ∩ # Reverse
øɽ⁋ # Right align and join by newlines
‛<>k/Ŀ # Replace "<>" with "/\"
Jelly, 19 bytes
Ỵz⁶UµOHØ^ṙaf⁶;`$)€G
While I was writing this, it tormented me to no end that the whole mess with af⁶;`$ could just be «, if the codepoint of backslash were somewhere closer to the ballpark of its forward companion. This can definitely be golfed further.
Ỵ Split the input on newlines.
z⁶ Transpose with space as filler.
U Reverse each row.
µ )€ For each character in each row:
Ø^ṙ rotate "/\" by
H half of
O the character's codepoint;
a vectorizing logical and with
; concatenate
f⁶ $ the character filtered to spaces
` to itself.
a (The slashes are unaffected if the filter removes everything.)
G Grid format: this builtin can do a lot of things,
but in this case it joins each row on spaces
then joins the rows on newlines.
Perl - 119
@l=map[/./g],reverse<>;do{print;$_=join(' ',map({'<'=>'/\\','>'=>'\/'}->{$_->[$b]}||' ',@l))."\n";$b++;}while(/[^
]/)
First, @l is assigned as a list of lists representing the characters on each line of input with lines in reverse order. Then it loops through the columns of characters, replacing the angle brackets with the corresponding slashes, joining the elements with spaces, and printing the joined slashes as a line.
Scala, 201 188 180 characters
(s:String)⇒(Seq("")→0/:s.lines.flatMap(l⇒Seq(l,l))){case((v,i),l)⇒(l.map(c⇒if(Set('>','<')(c))if(c%4==i)'/'else'\\'else c)+:v,2-i)}._1.init.transpose.map(_.mkString).mkString("\n")
note:
this only works if the provided string has all lines with equal length (i.e. padded with spaces)
explanation:
I'm using fold with initial value of tuple of a Seq[String] and an Int (instead of writing Seq.empty[String] im writing the shorter Seq("") and .init after the fold), the fold operates on a collection of strings, each string is a line in the original input, and every line is doubled. the trick here was to test for modulo of the char. since '<' value is 60, and '>' value is 62, testing for modulo 4, will yield 0 or 2. that's why the fold also carry a flipping Int set to 0. and flipped between 0 and 2 with 2-i. every odd line should map '>' to '/' and '<' to '\\', and every even line should map '>' to '\\' and '<' to '/'. this is why i test for c%4==i and hit 2 birds with 1 stone. the fold "rebuilds" the initial sequence of strings in reverse, and then (after dropping the last line), I transpose the sequence (this is why all strings must be of exact same length). because of the implicits involved, I need to _.mkString on each line (previously column), and then mkString("\n") for the final output.
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.
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.