12
\$\begingroup\$

Your task is to take an input string of ascii characters and output the string as a series of vertical words separated by spaces. An example is shown below:

Given the string:

Hello, World! My name is Foo.

the output should be:

H W M n i F
e o y a s o
l r   m   o
l l   e   .
o d
, !

10 bonus points will be awarded if your program correctly handles strings which need to wrap-around the terminal, which we'll set at 80 characters.

50 points if your program can also do the reverse!

\$\endgroup\$
  • \$\begingroup\$ Quite similar to Transpose a page of text. \$\endgroup\$ – manatwork Feb 21 '14 at 12:29
  • 3
    \$\begingroup\$ @manatwork: I suppose it is. It's not identical though - and I might argue my problem is a little easier. \$\endgroup\$ – Foo Barrigno Feb 21 '14 at 12:31
  • \$\begingroup\$ It's not 100% identical, but it's close enough to count as a duplicate: the reduction to make it identical is just replacing each space with two newlines. \$\endgroup\$ – Peter Taylor Feb 21 '14 at 14:04
  • 1
    \$\begingroup\$ @PeterTaylor: Not quite. My problem has no requirement to respect newlines in the original string. That problem requires that new lines be converted into spaces, and spaces converted into two newlines. It's not quite a trivial reduction. \$\endgroup\$ – Foo Barrigno Feb 21 '14 at 14:09

31 Answers 31

1
2
0
\$\begingroup\$

Julia - 109 bytes

i=split(readline());m=maximum(map(x->length(x),i));for c∈1:m println(join([rpad(w,m)[c] for w∈i]," "))end
| improve this answer | |
\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.