Hole type: one-liner
Write a one-liner that takes text from standard input and rotates it 180 degrees. In other words, it would take this input:
abcd 1234567 efgh
and produce this output:
hgfe 7654321 dcba
Extra leading or trailing newlines are not allowed.
Code | Length |
---|---|
perl -e'print reverse map{s/.*/reverse$&/e;$_}<>' | 49 |
perl -e'undef$/;print substr(reverse(<>),1)."\n"' | 49 |
perl -l -0e'print substr(reverse(<>),1)' | 40 |
perl -0pe'chop;$_=reverse."\n"' | 31 |
perl -l -0pe'chop;$_=reverse' | 29 |
This one works well as a golf problem, because rethinking one's approach can lead to a significantly shorter solution. In the first solution above, each line is reversed individually, and then the list of lines is reversed to finish the rotation. But, when one realizes that all the lines can be reversed as a single string, the solution can eventually be shortened to 29 characters, with the help of some command-line options.