Introduction
Write a complete program that rotates a rectangular block of ASCII characters 90 degrees clockwise. When the program itself is rotated 90 degrees clockwise, it rotates a block of ASCII characters 90 counterclockwise.
Rules
- You many not use built-ins that rotate or transpose matrices. For example, in MATLAB/Octave
rot90
and the transpose operator'
are not allowed. - You must write a complete program that uses STDIN and STDOUT or the closest equivalent.
- Your program must be rectangular and assume the input is also rectangular.
- The input and output are a newline separated strings and will not have trailing newlines.
When run with its source code as input, your program must rotate itself 90 degrees clockwise. The output must be a second program in the same language that rotates its input 90 degrees counterclockwise. When the rotated program is given its source code as input, it should output the source code of the original program.
Note: Both programs must work for any input, not just their own source code, so a one character quine is not allowed.
Example
Say the following is a valid program that rotates its input 90 degrees in a hypothetical language ExampleLang.
^f a2% 3
lk (^_^&
v
D8 $4 /
When run with itself as input, it outputs another valid program that rotates its input counterclockwise:
D l^
8 kf
$ (a
4 ^2
_%
^
/v&3
This second program, when given to itself as input, outputs the original program. Note that the blank line should have four spaces and there is a trailing space on the second to last line that cannot be rendered in markdown. To clarify:
$ examplelang program < program > rotProg
$ examplelang rotProg < rotProg > program1
$ diff -s program program1
Files program and program1 are identical
Shortest program wins. Standard loopholes are banned.