\$\begingroup\$
\$\endgroup\$
1
Rules
- Write a program in a language of your choice.
That program is designed to rotate a block of text. Example:
BOB 90 deg DCB CAT --> OAO DOG CW GTB
- You may assume the blocks of text are loaded into a variable
block
. - You may assume a square block, but of any size.
- You may assume the line-endings are
\n
. - You're not allowed to use a library that already rotates blocks of text.
- Code Golf rules, shortest program wins.
feersum
31.8k10 gold badges66 silver badges125 bronze badges
-
1\$\begingroup\$ Rotate in which direction? 90 degrees clockwise, or is that just an example? \$\endgroup\$algorithmshark– algorithmshark2014年09月25日 22:43:09 +00:00Commented Sep 25, 2014 at 22:43
2 Answers 2
\$\begingroup\$
\$\endgroup\$
2
GolfScript, 11 characters
n/-1%zip n*
Explanation:
n/ # split on newline
-1% # reverse array
zip # "rotate" (will turn ['abc' 'def' 'ghi'] into ['adg' 'beh' 'cfi'])
n* # join with newline again
answered Sep 25, 2014 at 22:42
-
\$\begingroup\$ Didn't he say that you cannot use an predefined method which rotates the text ? Seems like
zip
is doing that only \$\endgroup\$Optimizer– Optimizer2014年09月26日 16:57:56 +00:00Commented Sep 26, 2014 at 16:57 -
\$\begingroup\$ This can be improved by one char. See my answer to the question it duplicates \$\endgroup\$Peter Taylor– Peter Taylor2014年09月27日 16:51:35 +00:00Commented Sep 27, 2014 at 16:51
\$\begingroup\$
\$\endgroup\$
1
Python, 0 bytes
My program rotates the block of text by 720 degrees.
answered Sep 25, 2014 at 22:38
-
4\$\begingroup\$ Problem, it does not echo. \$\endgroup\$Christopher King– Christopher King2014年09月25日 23:19:26 +00:00Commented Sep 25, 2014 at 23:19