33
2
Sometimes when you're lying in bed and reading a message, your phone screen will pop into landscape mode right in the middle of a sentence. Only being able to read left to right, you find yourself incapacitated, unable to process the text in front of you.
To ensure that this won't happen again, you decide to make every message readable from any angle, whether your phone screen is rotated or mirrored. To make this happen, each message is printed as a square, with each side of the square containing the message, either in the original order or in reverse.
For backwards compatibility, the top side of the square should be the original message.
To make each message square as compact as possible, the first and last character of the message should be a part of two sides of the square. This means that the top side reads normally, the bottom side is in reverse, the left side reads top-bottom, and the right side reads bottom-top.
Input
A single string, with 2 or more characters. You should not assume that the string only contains alphanumerical characters or similar.
Output
The Squarification™ of the string. It is permissible to leave some whitespace at the end of each line, and a single newline at the end of the output.
Examples
Input: 'ab'
ab
ba
Input: 'abc'
abc
b b
cba
Input: 'Hello, world!'
Hello, world!
e d
l l
l r
o o
, w
w ,
o o
r l
l l
d e
!dlrow ,olleH
This challenge looks like A cube of text, but I'm hoping that it's different enough that there will be some clever answers.
As this is code-golf, get ready to trim some bytes!
Can the horizontal lines contain spaces between letters, as long as they align with margins? Example: the first line of output for
abc
would bea b c
. Alternatively, can we output a list of lines? Nice challenge, btw – Mr. Xcoder – 2018-10-08T06:30:49.977@Mr.Xcoder You may not have spaces in the middle of a line, so
abc
is alwaysabc
. EDIT: outputting a list of lines is allowed, just make sure that you have the joining in the footer so that answers can be verified easily. – maxb – 2018-10-08T06:52:45.473Can we return a list of lines? – Jo King – 2018-10-08T06:56:54.913
@JoKing Yes, a list of lines is allowed. – maxb – 2018-10-08T08:02:55.390
Related – Kevin Cruijssen – 2018-10-08T09:47:05.283
1"To ensure that this won't happen again, you decide to make every message readable from any angle, whether your phone screen is rotated or mirrored." - Or you could just, you know, enable the orientation lock for your phone... – Arnav Borborah – 2018-10-08T11:13:07.970
@ArnavBorborah That sounds very hard, what if you forget to enable it in a moment where your immediate response is required? – maxb – 2018-10-08T11:20:49.120
"To ensure that this won't happen again,". You do it once, and then keep it on for as long as you choose. ;) – Arnav Borborah – 2018-10-08T11:24:29.373
@maxb Is it ok if I take the input as an array of chars? – Luis felipe De jesus Munoz – 2018-10-08T12:59:36.280
@LuisfelipeDejesusMunoz I'm not sure what the consensus is on that. I've looked into some meta posts, and from what I've seen it seems like
char[]
should be treated as a string. That would imply that taking input as a list of chars is allowed. However, please correct me if I'm mistaken. – maxb – 2018-10-08T13:30:55.690Or you just add "rotate off" to your shortcuts that appear when you slide your finger from the top. ;-) – Erik the Outgolfer – 2018-10-08T13:33:35.580
@EriktheOutgolfer but in a state of great confusion, how will I know which side of the phone is the top? I'd much rather use a few bytes of my phone's memory to save myself from the embarrassment of a late reply. – maxb – 2018-10-08T13:36:37.547
@maxb You are allowed to decide on your own question whether an array of chars is okay or not, along with any other input formats (base64 encoded string, sum of the squares of the factors of the Unicode values modulo 42, etc) – Quintec – 2018-10-08T16:29:18.093
@Quintec I'll only allow modulo 43, get out of here with that non-prime modulo! Seriously though, thanks for the info, it'll help me with future challenges. – maxb – 2018-10-08T20:01:28.047
I suddenly have an urge to write an answer that takes input in that format – Quintec – 2018-10-08T20:08:08.417