Be there, for the square

The name of the pictureThe name of the pictureThe name of the pictureClash 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!










share|improve this question





















  • 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











  • Can we return a list of lines?
    – Jo King
    14 mins ago














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!










share|improve this question





















  • 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











  • Can we return a list of lines?
    – Jo King
    14 mins ago












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!










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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











  • 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











  • @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 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










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





share|improve this answer






















  • 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

















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!






share|improve this answer






















  • Outputting a list of lines is allowed! Also, -i-1 can be written as ~i to save two bytes.
    – maxb
    11 mins ago

















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!






share|improve this answer




















  • s[n+~i] saves 1 byte over n-i-1.
    – Mr. Xcoder
    1 min ago

















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!






share|improve this answer






















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "200"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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





    share|improve this answer






















    • 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














    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





    share|improve this answer






















    • 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












    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





    share|improve this answer















    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






    share|improve this answer














    share|improve this answer



    share|improve this answer








    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
















    • 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










    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!






    share|improve this answer






















    • Outputting a list of lines is allowed! Also, -i-1 can be written as ~i to save two bytes.
      – maxb
      11 mins ago














    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!






    share|improve this answer






















    • Outputting a list of lines is allowed! Also, -i-1 can be written as ~i to save two bytes.
      – maxb
      11 mins ago












    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!






    share|improve this answer














    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!







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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
















    • 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










    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!






    share|improve this answer




















    • s[n+~i] saves 1 byte over n-i-1.
      – Mr. Xcoder
      1 min ago














    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!






    share|improve this answer




















    • s[n+~i] saves 1 byte over n-i-1.
      – Mr. Xcoder
      1 min ago












    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!






    share|improve this answer













    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!







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 20 mins ago









    JS Guy

    37115




    37115











    • 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















    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










    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!






    share|improve this answer


























      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!






      share|improve this answer
























        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!






        share|improve this answer















        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!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 5 mins ago

























        answered 15 mins ago









        Shieru Asakoto

        1,850311




        1,850311



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            Confectionery