Be there, for the square
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
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!
code-golf string ascii-art
add a comment |Â
up vote
6
down vote
favorite
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!
code-golf string ascii-art
Can the horizontal lines contain spaces between letters, as long as they align with margins? Example: the first line of output forabc
would bea b c
. Alternatively, can we output a list of lines? Nice challenge, btw
– Mr. Xcoder
40 mins ago
@Mr.Xcoder You may not have spaces in the middle of a line, soabc
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
18 mins ago
Can we return a list of lines?
– Jo King
14 mins ago
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
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!
code-golf string ascii-art
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!
code-golf string ascii-art
code-golf string ascii-art
asked 1 hour ago


maxb
1,7381721
1,7381721
Can the horizontal lines contain spaces between letters, as long as they align with margins? Example: the first line of output forabc
would bea b c
. Alternatively, can we output a list of lines? Nice challenge, btw
– Mr. Xcoder
40 mins ago
@Mr.Xcoder You may not have spaces in the middle of a line, soabc
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
18 mins ago
Can we return a list of lines?
– Jo King
14 mins ago
add a comment |Â
Can the horizontal lines contain spaces between letters, as long as they align with margins? Example: the first line of output forabc
would bea b c
. Alternatively, can we output a list of lines? Nice challenge, btw
– Mr. Xcoder
40 mins ago
@Mr.Xcoder You may not have spaces in the middle of a line, soabc
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
18 mins ago
Can we return a list of lines?
– Jo King
14 mins ago
Can the horizontal lines contain spaces between letters, as long as they align with margins? Example: the first line of output for
abc
would be a b c
. Alternatively, can we output a list of lines? Nice challenge, btw– Mr. Xcoder
40 mins ago
Can the horizontal lines contain spaces between letters, as long as they align with margins? Example: the first line of output for
abc
would be a b c
. Alternatively, can we output a list of lines? Nice challenge, btw– Mr. Xcoder
40 mins ago
@Mr.Xcoder You may not have spaces in the middle of a line, so
abc
is always abc
. 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
18 mins ago
@Mr.Xcoder You may not have spaces in the middle of a line, so
abc
is always abc
. 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
18 mins ago
Can we return a list of lines?
– Jo King
14 mins ago
Can we return a list of lines?
– Jo King
14 mins ago
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
2
down vote
05AB1E, 12 bytes
gÃÂD)sûûŽ9¦SΛ
Try it online!
Explanation
g # length of input
ÃÂD # quadruplicate
) # wrap in a list
# these are the string lengths we'll print
s # push input
ûû # palendromize twice
# this is the string we'll print
Ž9¦S # push [2,4,6,0]
# these are the directions we'll print
Λ # paint on the canvas
This is just bizarre, very impressive!
– maxb
16 mins ago
@maxb: Will be interesting to see if Charcoal can do even shorter :)
– Emigna
14 mins ago
Wouldn't Canvas also be suitable for something like this? I haven't coded anything in it myself, but from the other answers I've seen in Canvas it seems to be perfect for printing stuff
– maxb
12 mins ago
add a comment |Â
up vote
2
down vote
Python 3, 78 76 Bytes
-2 bytes thanks to maxb!
lambda x:[x]+[x[i]+" "*(len(x)-2)+x[~i]for i in range(1,len(x)-1)]+[x[::-1]]
Try it Online!
Outputting a list of lines is allowed! Also,-i-1
can be written as~i
to save two bytes.
– maxb
11 mins ago
add a comment |Â
up vote
1
down vote
JavaScript (Node.js), 122 bytes
f=s=>o=s+"n";for(i=1,n=s.length;i<n-1;i++)o+=s[i]+' '.repeat(n-2)+s[n-i-1]+"n";o+=s.split``.reverse().join``;return o;
Try it online!
s[n+~i]
saves 1 byte overn-i-1
.
– Mr. Xcoder
1 min ago
add a comment |Â
up vote
0
down vote
JavaScript (Node.js), 101 99 bytes
x=>(i=0,j=l=x.length-1,y=[...x]).map(_=>i++?--j?x[i-1].padEnd(l)+x[j]:y.reverse().join``:x).join`
`
Try it online!
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
05AB1E, 12 bytes
gÃÂD)sûûŽ9¦SΛ
Try it online!
Explanation
g # length of input
ÃÂD # quadruplicate
) # wrap in a list
# these are the string lengths we'll print
s # push input
ûû # palendromize twice
# this is the string we'll print
Ž9¦S # push [2,4,6,0]
# these are the directions we'll print
Λ # paint on the canvas
This is just bizarre, very impressive!
– maxb
16 mins ago
@maxb: Will be interesting to see if Charcoal can do even shorter :)
– Emigna
14 mins ago
Wouldn't Canvas also be suitable for something like this? I haven't coded anything in it myself, but from the other answers I've seen in Canvas it seems to be perfect for printing stuff
– maxb
12 mins ago
add a comment |Â
up vote
2
down vote
05AB1E, 12 bytes
gÃÂD)sûûŽ9¦SΛ
Try it online!
Explanation
g # length of input
ÃÂD # quadruplicate
) # wrap in a list
# these are the string lengths we'll print
s # push input
ûû # palendromize twice
# this is the string we'll print
Ž9¦S # push [2,4,6,0]
# these are the directions we'll print
Λ # paint on the canvas
This is just bizarre, very impressive!
– maxb
16 mins ago
@maxb: Will be interesting to see if Charcoal can do even shorter :)
– Emigna
14 mins ago
Wouldn't Canvas also be suitable for something like this? I haven't coded anything in it myself, but from the other answers I've seen in Canvas it seems to be perfect for printing stuff
– maxb
12 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
05AB1E, 12 bytes
gÃÂD)sûûŽ9¦SΛ
Try it online!
Explanation
g # length of input
ÃÂD # quadruplicate
) # wrap in a list
# these are the string lengths we'll print
s # push input
ûû # palendromize twice
# this is the string we'll print
Ž9¦S # push [2,4,6,0]
# these are the directions we'll print
Λ # paint on the canvas
05AB1E, 12 bytes
gÃÂD)sûûŽ9¦SΛ
Try it online!
Explanation
g # length of input
ÃÂD # quadruplicate
) # wrap in a list
# these are the string lengths we'll print
s # push input
ûû # palendromize twice
# this is the string we'll print
Ž9¦S # push [2,4,6,0]
# these are the directions we'll print
Λ # paint on the canvas
edited 21 mins ago
answered 38 mins ago


Emigna
43.7k431132
43.7k431132
This is just bizarre, very impressive!
– maxb
16 mins ago
@maxb: Will be interesting to see if Charcoal can do even shorter :)
– Emigna
14 mins ago
Wouldn't Canvas also be suitable for something like this? I haven't coded anything in it myself, but from the other answers I've seen in Canvas it seems to be perfect for printing stuff
– maxb
12 mins ago
add a comment |Â
This is just bizarre, very impressive!
– maxb
16 mins ago
@maxb: Will be interesting to see if Charcoal can do even shorter :)
– Emigna
14 mins ago
Wouldn't Canvas also be suitable for something like this? I haven't coded anything in it myself, but from the other answers I've seen in Canvas it seems to be perfect for printing stuff
– maxb
12 mins ago
This is just bizarre, very impressive!
– maxb
16 mins ago
This is just bizarre, very impressive!
– maxb
16 mins ago
@maxb: Will be interesting to see if Charcoal can do even shorter :)
– Emigna
14 mins ago
@maxb: Will be interesting to see if Charcoal can do even shorter :)
– Emigna
14 mins ago
Wouldn't Canvas also be suitable for something like this? I haven't coded anything in it myself, but from the other answers I've seen in Canvas it seems to be perfect for printing stuff
– maxb
12 mins ago
Wouldn't Canvas also be suitable for something like this? I haven't coded anything in it myself, but from the other answers I've seen in Canvas it seems to be perfect for printing stuff
– maxb
12 mins ago
add a comment |Â
up vote
2
down vote
Python 3, 78 76 Bytes
-2 bytes thanks to maxb!
lambda x:[x]+[x[i]+" "*(len(x)-2)+x[~i]for i in range(1,len(x)-1)]+[x[::-1]]
Try it Online!
Outputting a list of lines is allowed! Also,-i-1
can be written as~i
to save two bytes.
– maxb
11 mins ago
add a comment |Â
up vote
2
down vote
Python 3, 78 76 Bytes
-2 bytes thanks to maxb!
lambda x:[x]+[x[i]+" "*(len(x)-2)+x[~i]for i in range(1,len(x)-1)]+[x[::-1]]
Try it Online!
Outputting a list of lines is allowed! Also,-i-1
can be written as~i
to save two bytes.
– maxb
11 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Python 3, 78 76 Bytes
-2 bytes thanks to maxb!
lambda x:[x]+[x[i]+" "*(len(x)-2)+x[~i]for i in range(1,len(x)-1)]+[x[::-1]]
Try it Online!
Python 3, 78 76 Bytes
-2 bytes thanks to maxb!
lambda x:[x]+[x[i]+" "*(len(x)-2)+x[~i]for i in range(1,len(x)-1)]+[x[::-1]]
Try it Online!
edited 7 mins ago
answered 22 mins ago


Zachary Cotton
44915
44915
Outputting a list of lines is allowed! Also,-i-1
can be written as~i
to save two bytes.
– maxb
11 mins ago
add a comment |Â
Outputting a list of lines is allowed! Also,-i-1
can be written as~i
to save two bytes.
– maxb
11 mins ago
Outputting a list of lines is allowed! Also,
-i-1
can be written as ~i
to save two bytes.– maxb
11 mins ago
Outputting a list of lines is allowed! Also,
-i-1
can be written as ~i
to save two bytes.– maxb
11 mins ago
add a comment |Â
up vote
1
down vote
JavaScript (Node.js), 122 bytes
f=s=>o=s+"n";for(i=1,n=s.length;i<n-1;i++)o+=s[i]+' '.repeat(n-2)+s[n-i-1]+"n";o+=s.split``.reverse().join``;return o;
Try it online!
s[n+~i]
saves 1 byte overn-i-1
.
– Mr. Xcoder
1 min ago
add a comment |Â
up vote
1
down vote
JavaScript (Node.js), 122 bytes
f=s=>o=s+"n";for(i=1,n=s.length;i<n-1;i++)o+=s[i]+' '.repeat(n-2)+s[n-i-1]+"n";o+=s.split``.reverse().join``;return o;
Try it online!
s[n+~i]
saves 1 byte overn-i-1
.
– Mr. Xcoder
1 min ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
JavaScript (Node.js), 122 bytes
f=s=>o=s+"n";for(i=1,n=s.length;i<n-1;i++)o+=s[i]+' '.repeat(n-2)+s[n-i-1]+"n";o+=s.split``.reverse().join``;return o;
Try it online!
JavaScript (Node.js), 122 bytes
f=s=>o=s+"n";for(i=1,n=s.length;i<n-1;i++)o+=s[i]+' '.repeat(n-2)+s[n-i-1]+"n";o+=s.split``.reverse().join``;return o;
Try it online!
answered 20 mins ago
JS Guy
37115
37115
s[n+~i]
saves 1 byte overn-i-1
.
– Mr. Xcoder
1 min ago
add a comment |Â
s[n+~i]
saves 1 byte overn-i-1
.
– Mr. Xcoder
1 min ago
s[n+~i]
saves 1 byte over n-i-1
.– Mr. Xcoder
1 min ago
s[n+~i]
saves 1 byte over n-i-1
.– Mr. Xcoder
1 min ago
add a comment |Â
up vote
0
down vote
JavaScript (Node.js), 101 99 bytes
x=>(i=0,j=l=x.length-1,y=[...x]).map(_=>i++?--j?x[i-1].padEnd(l)+x[j]:y.reverse().join``:x).join`
`
Try it online!
add a comment |Â
up vote
0
down vote
JavaScript (Node.js), 101 99 bytes
x=>(i=0,j=l=x.length-1,y=[...x]).map(_=>i++?--j?x[i-1].padEnd(l)+x[j]:y.reverse().join``:x).join`
`
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
JavaScript (Node.js), 101 99 bytes
x=>(i=0,j=l=x.length-1,y=[...x]).map(_=>i++?--j?x[i-1].padEnd(l)+x[j]:y.reverse().join``:x).join`
`
Try it online!
JavaScript (Node.js), 101 99 bytes
x=>(i=0,j=l=x.length-1,y=[...x]).map(_=>i++?--j?x[i-1].padEnd(l)+x[j]:y.reverse().join``:x).join`
`
Try it online!
edited 5 mins ago
answered 15 mins ago
Shieru Asakoto
1,850311
1,850311
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f173635%2fbe-there-for-the-square%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
40 mins ago
@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
18 mins ago
Can we return a list of lines?
– Jo King
14 mins ago