05AB1E、スコア8 -20 -21(30 29 バイト -50ボーナス):
|Dgi#ζεSðý}»}ë¹ε2ô€¬}ζJεðÜ}ðý
オンラインで試してください(通常の単一行入力)。
オンラインで試してみてください(複数行反転入力)。
説明:
| # 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)
元の8バイトの回答:
#ζεSðý}»
オンラインでお試しください。
説明:
# # 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)