05AB1E, score 8 -20 -21 (30 29 bytes - 50 bonus):
|Dgi#ζεSðý}»}ë¹ε2ô€¬}ζJεðÜ}ðý
Try it online (regular single-line input).
Try it online (multi-line reversed input).
Explanation:
| # Take the input split on newlines:
# i.e. 'This is a test' → ['This is a test']
# i.e. 'T i a t\nh s e\ni s\ns t'
# → ['T i a t','h s e','i s','s t']
Dg # Duplicate this list, and take the length
# i.e. ['This is a test'] → 1
# i.e. ['T i a t','h s e','i s','s t'] → 4
i } # If the length is exactly 1:
¹ # Take the input again
# # Split the input-string by spaces
# i.e. 'This is a test' → ['This','is','a','test']
ζ # Zip with space-filler: Swap all rows and columns
# i.e. ['This','is','a','test'] → ['Tiat','hs e','i s','s t']
ε } # For each item:
S # Convert the item to a list of characters
# i.e. 'Tiat' → ['T','i','a','t']
ðý # Join them by a single space
# i.e. ['T','i','a','t'] → 'T i a t'
» # Join the result by newlines (and output implicitly)
ë # Else:
ε } # For each item:
2ô # Split it into chunks of two characters
# i.e. 'h s e' → ['h ','s ',' ','e']
€¬ # Take the head (first character) of each:
# i.e. ['h ','s ',' ','e'] → ['h','s',' ','e']
ζ # Zip with space-filler: Swap all rows and columns
# i.e. [['T','i','a','t'],['h','s',' ','e'],['i',' ',' ','s'],['s',' ',' ','t']]
# → [['T','h','i','s'],['i','s',' ',' '],['a',' ',' ',' '],['t','e','s','t']]
J # Join each inner list to a single string
# i.e. [['T','h','i','s'],['i','s',' ',' '],['a',' ',' ',' '],['t','e','s','t']]
# → ['This','is ','a ','test']
ε } # For each item:
ðÜ # Remove any trailing spaces
# i.e. 'is ' → 'is'
ðý # Join the items by a single space (and output implicitly)
Original 8-byte answer:
#ζεSðý}»
Try it online.
Explanation:
# # Split the input-string by spaces
# i.e. 'This is a test' → ['This','is','a','test']
ζ # Zip with space-filler: Swap all rows and columns
# i.e. ['This','is','a','test'] → ['Tiat','hs e','i s','s t']
ε } # For each item:
S # Convert the item to a list of characters
# i.e. 'Tiat' → ['T','i','a','t']
ðý # Join them by a single space
# i.e. ['T','i','a','t'] → 'T i a t'
» # Join the result by newlines (and output implicitly)
Quite similar to Transpose a page of text.
– manatwork – 2014-02-21T12:29:19.5903@manatwork: I suppose it is. It's not identical though - and I might argue my problem is a little easier. – Foo Barrigno – 2014-02-21T12:31:44.887
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. – Peter Taylor – 2014-02-21T14:04:11.620
1@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. – Foo Barrigno – 2014-02-21T14:09:32.180