Build ASCII Podiums












7












$begingroup$


In sporting competitions, it often happens that winners are presented on podiums, with the first-place person on the highest in the middle, the second-place person on the middle height to the left, and the third-place person on the lowest and to the right. We're going to recreate that here with some special tweaks.



The podiums are presented below:



     @---@
| @ |
@---@| | |
| @ || | |
| | || | |@---@
| | || | || @ |


This will form the basis for this challenge. The next step is to make the podiums wide enough to fit the people (printable ASCII strings) that are on them. However, we want to ensure aesthetic beauty (because this is a fantastic photo opportunity), so each podium needs to be the same width, and the width must be odd. Additionally, the people will (obviously) want to stand in the center of the podium, so the strings must be centered as best as possible. (You can align to either the left or the right, and it doesn't need to be consistent.) The above podiums are the minimum size, and are considered 3 wide.



For example, given the input ["Tom", "Ann", "Sue"] representing first-, second-, and third-place respectively, output the following podiums:



      Tom
@---@
Ann | @ |
@---@| | |
| @ || | | Sue
| | || | |@---@
| | || | || @ |


However, if we have Anne instead of Ann, we'll need to go up to the next size, 5, and center the strings as best as possible. Here, I'm aligning so the "extra" letter of Anne is to the left of center, but you can choose which side to align to.



         Tom
@-----@
Anne | @ |
@-----@| | |
| @ || | | Sue
| | || | |@-----@
| | || | || @ |


Let's go for some longer names. How about ["William", "Brad", "Eugene"]:



          William
@-------@
Brad | @ |
@-------@| | |
| @ || | | Eugene
| | || | |@-------@
| | || | || @ |


Here we can see that Brad has a lot of whitespace, Eugene less so, and William fits just right.



For a longer test case, how about ["A", "BC", "DEFGHIJKLMNOPQRSTUVWXYZ"]:



                                     A
@-----------------------@
BC | @ |
@-----------------------@| | |
| @ || | | DEFGHIJKLMNOPQRSTUVWXYZ
| | || | |@-----------------------@
| | || | || @ |


Finally, we have the smallest possible input, something like ["A", "B", "C"]:



       A
@---@
B | @ |
@---@| | |
| @ || | | C
| | || | |@---@
| | || | || @ |





  • Input and output can be given by any convenient method.

  • The input is guaranteed non-empty (i.e., you'll never receive "" as a name).

  • You can print it to STDOUT or return it as a function result.

  • Either a full program or a function are acceptable.

  • Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.


  • Standard loopholes are forbidden.

  • This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.










share|improve this question











$endgroup$












  • $begingroup$
    Do all even-length names have to be aligned in the same direction?
    $endgroup$
    – Sparr
    28 mins ago
















7












$begingroup$


In sporting competitions, it often happens that winners are presented on podiums, with the first-place person on the highest in the middle, the second-place person on the middle height to the left, and the third-place person on the lowest and to the right. We're going to recreate that here with some special tweaks.



The podiums are presented below:



     @---@
| @ |
@---@| | |
| @ || | |
| | || | |@---@
| | || | || @ |


This will form the basis for this challenge. The next step is to make the podiums wide enough to fit the people (printable ASCII strings) that are on them. However, we want to ensure aesthetic beauty (because this is a fantastic photo opportunity), so each podium needs to be the same width, and the width must be odd. Additionally, the people will (obviously) want to stand in the center of the podium, so the strings must be centered as best as possible. (You can align to either the left or the right, and it doesn't need to be consistent.) The above podiums are the minimum size, and are considered 3 wide.



For example, given the input ["Tom", "Ann", "Sue"] representing first-, second-, and third-place respectively, output the following podiums:



      Tom
@---@
Ann | @ |
@---@| | |
| @ || | | Sue
| | || | |@---@
| | || | || @ |


However, if we have Anne instead of Ann, we'll need to go up to the next size, 5, and center the strings as best as possible. Here, I'm aligning so the "extra" letter of Anne is to the left of center, but you can choose which side to align to.



         Tom
@-----@
Anne | @ |
@-----@| | |
| @ || | | Sue
| | || | |@-----@
| | || | || @ |


Let's go for some longer names. How about ["William", "Brad", "Eugene"]:



          William
@-------@
Brad | @ |
@-------@| | |
| @ || | | Eugene
| | || | |@-------@
| | || | || @ |


Here we can see that Brad has a lot of whitespace, Eugene less so, and William fits just right.



For a longer test case, how about ["A", "BC", "DEFGHIJKLMNOPQRSTUVWXYZ"]:



                                     A
@-----------------------@
BC | @ |
@-----------------------@| | |
| @ || | | DEFGHIJKLMNOPQRSTUVWXYZ
| | || | |@-----------------------@
| | || | || @ |


Finally, we have the smallest possible input, something like ["A", "B", "C"]:



       A
@---@
B | @ |
@---@| | |
| @ || | | C
| | || | |@---@
| | || | || @ |





  • Input and output can be given by any convenient method.

  • The input is guaranteed non-empty (i.e., you'll never receive "" as a name).

  • You can print it to STDOUT or return it as a function result.

  • Either a full program or a function are acceptable.

  • Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.


  • Standard loopholes are forbidden.

  • This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.










share|improve this question











$endgroup$












  • $begingroup$
    Do all even-length names have to be aligned in the same direction?
    $endgroup$
    – Sparr
    28 mins ago














7












7








7





$begingroup$


In sporting competitions, it often happens that winners are presented on podiums, with the first-place person on the highest in the middle, the second-place person on the middle height to the left, and the third-place person on the lowest and to the right. We're going to recreate that here with some special tweaks.



The podiums are presented below:



     @---@
| @ |
@---@| | |
| @ || | |
| | || | |@---@
| | || | || @ |


This will form the basis for this challenge. The next step is to make the podiums wide enough to fit the people (printable ASCII strings) that are on them. However, we want to ensure aesthetic beauty (because this is a fantastic photo opportunity), so each podium needs to be the same width, and the width must be odd. Additionally, the people will (obviously) want to stand in the center of the podium, so the strings must be centered as best as possible. (You can align to either the left or the right, and it doesn't need to be consistent.) The above podiums are the minimum size, and are considered 3 wide.



For example, given the input ["Tom", "Ann", "Sue"] representing first-, second-, and third-place respectively, output the following podiums:



      Tom
@---@
Ann | @ |
@---@| | |
| @ || | | Sue
| | || | |@---@
| | || | || @ |


However, if we have Anne instead of Ann, we'll need to go up to the next size, 5, and center the strings as best as possible. Here, I'm aligning so the "extra" letter of Anne is to the left of center, but you can choose which side to align to.



         Tom
@-----@
Anne | @ |
@-----@| | |
| @ || | | Sue
| | || | |@-----@
| | || | || @ |


Let's go for some longer names. How about ["William", "Brad", "Eugene"]:



          William
@-------@
Brad | @ |
@-------@| | |
| @ || | | Eugene
| | || | |@-------@
| | || | || @ |


Here we can see that Brad has a lot of whitespace, Eugene less so, and William fits just right.



For a longer test case, how about ["A", "BC", "DEFGHIJKLMNOPQRSTUVWXYZ"]:



                                     A
@-----------------------@
BC | @ |
@-----------------------@| | |
| @ || | | DEFGHIJKLMNOPQRSTUVWXYZ
| | || | |@-----------------------@
| | || | || @ |


Finally, we have the smallest possible input, something like ["A", "B", "C"]:



       A
@---@
B | @ |
@---@| | |
| @ || | | C
| | || | |@---@
| | || | || @ |





  • Input and output can be given by any convenient method.

  • The input is guaranteed non-empty (i.e., you'll never receive "" as a name).

  • You can print it to STDOUT or return it as a function result.

  • Either a full program or a function are acceptable.

  • Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.


  • Standard loopholes are forbidden.

  • This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.










share|improve this question











$endgroup$




In sporting competitions, it often happens that winners are presented on podiums, with the first-place person on the highest in the middle, the second-place person on the middle height to the left, and the third-place person on the lowest and to the right. We're going to recreate that here with some special tweaks.



The podiums are presented below:



     @---@
| @ |
@---@| | |
| @ || | |
| | || | |@---@
| | || | || @ |


This will form the basis for this challenge. The next step is to make the podiums wide enough to fit the people (printable ASCII strings) that are on them. However, we want to ensure aesthetic beauty (because this is a fantastic photo opportunity), so each podium needs to be the same width, and the width must be odd. Additionally, the people will (obviously) want to stand in the center of the podium, so the strings must be centered as best as possible. (You can align to either the left or the right, and it doesn't need to be consistent.) The above podiums are the minimum size, and are considered 3 wide.



For example, given the input ["Tom", "Ann", "Sue"] representing first-, second-, and third-place respectively, output the following podiums:



      Tom
@---@
Ann | @ |
@---@| | |
| @ || | | Sue
| | || | |@---@
| | || | || @ |


However, if we have Anne instead of Ann, we'll need to go up to the next size, 5, and center the strings as best as possible. Here, I'm aligning so the "extra" letter of Anne is to the left of center, but you can choose which side to align to.



         Tom
@-----@
Anne | @ |
@-----@| | |
| @ || | | Sue
| | || | |@-----@
| | || | || @ |


Let's go for some longer names. How about ["William", "Brad", "Eugene"]:



          William
@-------@
Brad | @ |
@-------@| | |
| @ || | | Eugene
| | || | |@-------@
| | || | || @ |


Here we can see that Brad has a lot of whitespace, Eugene less so, and William fits just right.



For a longer test case, how about ["A", "BC", "DEFGHIJKLMNOPQRSTUVWXYZ"]:



                                     A
@-----------------------@
BC | @ |
@-----------------------@| | |
| @ || | | DEFGHIJKLMNOPQRSTUVWXYZ
| | || | |@-----------------------@
| | || | || @ |


Finally, we have the smallest possible input, something like ["A", "B", "C"]:



       A
@---@
B | @ |
@---@| | |
| @ || | | C
| | || | |@---@
| | || | || @ |





  • Input and output can be given by any convenient method.

  • The input is guaranteed non-empty (i.e., you'll never receive "" as a name).

  • You can print it to STDOUT or return it as a function result.

  • Either a full program or a function are acceptable.

  • Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.


  • Standard loopholes are forbidden.

  • This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.







code-golf ascii-art






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 6 hours ago







AdmBorkBork

















asked 7 hours ago









AdmBorkBorkAdmBorkBork

27.2k366234




27.2k366234












  • $begingroup$
    Do all even-length names have to be aligned in the same direction?
    $endgroup$
    – Sparr
    28 mins ago


















  • $begingroup$
    Do all even-length names have to be aligned in the same direction?
    $endgroup$
    – Sparr
    28 mins ago
















$begingroup$
Do all even-length names have to be aligned in the same direction?
$endgroup$
– Sparr
28 mins ago




$begingroup$
Do all even-length names have to be aligned in the same direction?
$endgroup$
– Sparr
28 mins ago










4 Answers
4






active

oldest

votes


















2












$begingroup$

JavaScript (ES8), 196 bytes





a=>`141
101
521
031
236
330
332`.replace(/./g,n=>[...`@-@ |@||||`.substr(n*3,3)].join(' -'[+!+n].repeat(m/2))||a[n-=4].padStart(m+l[n]+3>>1).padEnd(m+3),m=Math.max(2,...l=a.map(s=>s.length))&~1)


Try it online!






share|improve this answer











$endgroup$





















    0












    $begingroup$


    Groovy, 187, 176 bytes



    f={n->m=n*.size().max()|1;h=' '*(m/2);[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{println(it.sum{(n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"])[it]})}}


    Try it online!



    Defines a closure f which can be called via:



    f(['tom','ann','sue'])


    prints to std out.



    Explanation:



    Unobfuscating the code, we have:



    f={n->
    m=n*.size().max()|1
    h=' '*(m/2)
    a=n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"]
    [[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{
    println(it.sum{a[it]})
    }
    }




    • f={n-> - define closure f with one in-param n


    • m=n*.size().max()|1 - find max name len, binary-or to odd number


    • h=' '*(m/2) - h will contain floor(m/2) spaces, used later


    • a=...- creates an encoding list with elements:


      • indexes 0,1,2 - names, centered to max len

      • index 3 - m+2 spaces

      • index 4 - @---@ pattern, padded to len

      • index 5 - | @ | pattern, padded to len

      • index 6 - | | | pattern, padded to len




    • [[3,0],...].any{...}- use indicies into the encoding list to build and print the result


    • println(it.sum{a[it]}) - use the fact that string + string works in groovy and call sum on the list of indicies

    • note in the answer the variable a has been inlined,nelines removed etc.






    share|improve this answer











    $endgroup$





















      0












      $begingroup$


      Canvas, 45 bytes



      r351⁰{|*@;∔;J└l2M2%±├ ××l⇵╷-×└+-α∔k+│∔⇵;}┐++⇵


      Try it here!



      Explanation:



      r    Center the input, preferring left. Converts to an ASCII-art object
      which pads everything with spaces. This is the bulk of the magic.

      251⁰{ .... } for each number in [2, 5, 1]:
      |* repeat "|" vertically that many times
      @;∔ prepend an "@" - a vertical bar for later
      ; swap top 2 stack items - put the centered art on top
      J push the 1st line of it (removing it from the art)
      └ order the stack to [remaining, "@¶|¶|..", currentLine]
      l get the length of the current line
      2M max of that and 2
      2% that % 2
      ±├ (-that) + 2
      ×× prepend (-max(len,2)%2) + 2 spaces
      l get the length of the new string
      ⇵╷ ceil(len / 2) -1
      -× repeat "-" that many times - half of the podiums top
      └ order stack to [art, currLine, "@¶|¶|..", "----"]
      + append the dashes to the vertical bar = "@-----¶|¶|.."
      -α∔ vertically add "-" and the original vertical bar - "-¶@¶|¶|.."
      k remove the last line of that to make up for the middles shortness
      + and append that horizontally - half of the podium without the name
      │ palindromize the podium
      ∔ and prepend the name
      ⇵ reverse vertically so the outputs could be aligned to the bottom
      ; and get the rest of the centered input on top
      Finally,
      ┐ remove the useless now-empty input
      ++ join the 3 podium parts together
      ⇵ and undo the reversing


      Abuses "and it doesn't need to be consistent", making it pretty unintelligible.






      share|improve this answer











      $endgroup$













      • $begingroup$
        Umm...any chance of an explanation?
        $endgroup$
        – Matias Bjarland
        2 hours ago










      • $begingroup$
        @MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
        $endgroup$
        – dzaima
        2 hours ago



















      0












      $begingroup$


      Charcoal, 63 bytes



      ≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⟧≔⁻⁷ⅉιP↓ι@ηP↓ιP↓@@¹ηP↓ι@


      Try it online! Link is to verbose version of code. Explanation:



      ≔÷⌈EθLι²η


      Calculate the number of spaces in each half of a podium.



      F³«


      Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.



      J×ι⁺³⊗η⊗﹪⁻¹ι³


      Position to the start of the line that will have the text.



      ⟦◧§θι⁺⊕η⊘⊕L§θι⟧


      Output the text with enough left padding to centre it.



      ≔⁻⁷ⅉι


      Get the height of the podium.



      P↓ι@ηP↓ιP↓@@¹ηP↓ι@


      Draw the podium.



      Alternative approach, also 63 bytes:



      ≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⪫@-@×-η⟧E⁻⁷ⅉ⪫⪫||§|@¬κ× η


      Try it online! Link is to verbose version of code. Explanation:



      ≔÷⌈EθLι²η


      Calculate the number of spaces in each half of a podium.



      F³«


      Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.



      J×ι⁺³⊗η⊗﹪⁻¹ι³


      Position to the start of the line that will have the text.



      ⟦◧§θι⁺⊕η⊘⊕L§θι


      Output the text with enough left padding to centre it.



      ⪫@-@×-η⟧


      Also output the top of the podium by inserting -s between the characters of the string @-@ to reach the correct width.



      E⁻⁷ⅉ⪫⪫||§|@¬κ× η


      Print the remainder of the podium by spacing the |s appropriately, except that the middle character is a @ on the first row.






      share|improve this answer









      $endgroup$













        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',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        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%2f180187%2fbuild-ascii-podiums%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2












        $begingroup$

        JavaScript (ES8), 196 bytes





        a=>`141
        101
        521
        031
        236
        330
        332`.replace(/./g,n=>[...`@-@ |@||||`.substr(n*3,3)].join(' -'[+!+n].repeat(m/2))||a[n-=4].padStart(m+l[n]+3>>1).padEnd(m+3),m=Math.max(2,...l=a.map(s=>s.length))&~1)


        Try it online!






        share|improve this answer











        $endgroup$


















          2












          $begingroup$

          JavaScript (ES8), 196 bytes





          a=>`141
          101
          521
          031
          236
          330
          332`.replace(/./g,n=>[...`@-@ |@||||`.substr(n*3,3)].join(' -'[+!+n].repeat(m/2))||a[n-=4].padStart(m+l[n]+3>>1).padEnd(m+3),m=Math.max(2,...l=a.map(s=>s.length))&~1)


          Try it online!






          share|improve this answer











          $endgroup$
















            2












            2








            2





            $begingroup$

            JavaScript (ES8), 196 bytes





            a=>`141
            101
            521
            031
            236
            330
            332`.replace(/./g,n=>[...`@-@ |@||||`.substr(n*3,3)].join(' -'[+!+n].repeat(m/2))||a[n-=4].padStart(m+l[n]+3>>1).padEnd(m+3),m=Math.max(2,...l=a.map(s=>s.length))&~1)


            Try it online!






            share|improve this answer











            $endgroup$



            JavaScript (ES8), 196 bytes





            a=>`141
            101
            521
            031
            236
            330
            332`.replace(/./g,n=>[...`@-@ |@||||`.substr(n*3,3)].join(' -'[+!+n].repeat(m/2))||a[n-=4].padStart(m+l[n]+3>>1).padEnd(m+3),m=Math.max(2,...l=a.map(s=>s.length))&~1)


            Try it online!







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 6 hours ago

























            answered 6 hours ago









            ArnauldArnauld

            76.4k693321




            76.4k693321























                0












                $begingroup$


                Groovy, 187, 176 bytes



                f={n->m=n*.size().max()|1;h=' '*(m/2);[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{println(it.sum{(n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"])[it]})}}


                Try it online!



                Defines a closure f which can be called via:



                f(['tom','ann','sue'])


                prints to std out.



                Explanation:



                Unobfuscating the code, we have:



                f={n->
                m=n*.size().max()|1
                h=' '*(m/2)
                a=n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"]
                [[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{
                println(it.sum{a[it]})
                }
                }




                • f={n-> - define closure f with one in-param n


                • m=n*.size().max()|1 - find max name len, binary-or to odd number


                • h=' '*(m/2) - h will contain floor(m/2) spaces, used later


                • a=...- creates an encoding list with elements:


                  • indexes 0,1,2 - names, centered to max len

                  • index 3 - m+2 spaces

                  • index 4 - @---@ pattern, padded to len

                  • index 5 - | @ | pattern, padded to len

                  • index 6 - | | | pattern, padded to len




                • [[3,0],...].any{...}- use indicies into the encoding list to build and print the result


                • println(it.sum{a[it]}) - use the fact that string + string works in groovy and call sum on the list of indicies

                • note in the answer the variable a has been inlined,nelines removed etc.






                share|improve this answer











                $endgroup$


















                  0












                  $begingroup$


                  Groovy, 187, 176 bytes



                  f={n->m=n*.size().max()|1;h=' '*(m/2);[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{println(it.sum{(n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"])[it]})}}


                  Try it online!



                  Defines a closure f which can be called via:



                  f(['tom','ann','sue'])


                  prints to std out.



                  Explanation:



                  Unobfuscating the code, we have:



                  f={n->
                  m=n*.size().max()|1
                  h=' '*(m/2)
                  a=n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"]
                  [[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{
                  println(it.sum{a[it]})
                  }
                  }




                  • f={n-> - define closure f with one in-param n


                  • m=n*.size().max()|1 - find max name len, binary-or to odd number


                  • h=' '*(m/2) - h will contain floor(m/2) spaces, used later


                  • a=...- creates an encoding list with elements:


                    • indexes 0,1,2 - names, centered to max len

                    • index 3 - m+2 spaces

                    • index 4 - @---@ pattern, padded to len

                    • index 5 - | @ | pattern, padded to len

                    • index 6 - | | | pattern, padded to len




                  • [[3,0],...].any{...}- use indicies into the encoding list to build and print the result


                  • println(it.sum{a[it]}) - use the fact that string + string works in groovy and call sum on the list of indicies

                  • note in the answer the variable a has been inlined,nelines removed etc.






                  share|improve this answer











                  $endgroup$
















                    0












                    0








                    0





                    $begingroup$


                    Groovy, 187, 176 bytes



                    f={n->m=n*.size().max()|1;h=' '*(m/2);[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{println(it.sum{(n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"])[it]})}}


                    Try it online!



                    Defines a closure f which can be called via:



                    f(['tom','ann','sue'])


                    prints to std out.



                    Explanation:



                    Unobfuscating the code, we have:



                    f={n->
                    m=n*.size().max()|1
                    h=' '*(m/2)
                    a=n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"]
                    [[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{
                    println(it.sum{a[it]})
                    }
                    }




                    • f={n-> - define closure f with one in-param n


                    • m=n*.size().max()|1 - find max name len, binary-or to odd number


                    • h=' '*(m/2) - h will contain floor(m/2) spaces, used later


                    • a=...- creates an encoding list with elements:


                      • indexes 0,1,2 - names, centered to max len

                      • index 3 - m+2 spaces

                      • index 4 - @---@ pattern, padded to len

                      • index 5 - | @ | pattern, padded to len

                      • index 6 - | | | pattern, padded to len




                    • [[3,0],...].any{...}- use indicies into the encoding list to build and print the result


                    • println(it.sum{a[it]}) - use the fact that string + string works in groovy and call sum on the list of indicies

                    • note in the answer the variable a has been inlined,nelines removed etc.






                    share|improve this answer











                    $endgroup$




                    Groovy, 187, 176 bytes



                    f={n->m=n*.size().max()|1;h=' '*(m/2);[[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{println(it.sum{(n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"])[it]})}}


                    Try it online!



                    Defines a closure f which can be called via:



                    f(['tom','ann','sue'])


                    prints to std out.



                    Explanation:



                    Unobfuscating the code, we have:



                    f={n->
                    m=n*.size().max()|1
                    h=' '*(m/2)
                    a=n*.center(m+2)+[' '*(m+2),"@${'-'*m}@","|$h@$h|","|$h|$h|"]
                    [[3,0],[3,4],[1,5],[4,6],[5,6,2],[6,6,4],[6,6,5]].any{
                    println(it.sum{a[it]})
                    }
                    }




                    • f={n-> - define closure f with one in-param n


                    • m=n*.size().max()|1 - find max name len, binary-or to odd number


                    • h=' '*(m/2) - h will contain floor(m/2) spaces, used later


                    • a=...- creates an encoding list with elements:


                      • indexes 0,1,2 - names, centered to max len

                      • index 3 - m+2 spaces

                      • index 4 - @---@ pattern, padded to len

                      • index 5 - | @ | pattern, padded to len

                      • index 6 - | | | pattern, padded to len




                    • [[3,0],...].any{...}- use indicies into the encoding list to build and print the result


                    • println(it.sum{a[it]}) - use the fact that string + string works in groovy and call sum on the list of indicies

                    • note in the answer the variable a has been inlined,nelines removed etc.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited 2 hours ago

























                    answered 3 hours ago









                    Matias BjarlandMatias Bjarland

                    34016




                    34016























                        0












                        $begingroup$


                        Canvas, 45 bytes



                        r351⁰{|*@;∔;J└l2M2%±├ ××l⇵╷-×└+-α∔k+│∔⇵;}┐++⇵


                        Try it here!



                        Explanation:



                        r    Center the input, preferring left. Converts to an ASCII-art object
                        which pads everything with spaces. This is the bulk of the magic.

                        251⁰{ .... } for each number in [2, 5, 1]:
                        |* repeat "|" vertically that many times
                        @;∔ prepend an "@" - a vertical bar for later
                        ; swap top 2 stack items - put the centered art on top
                        J push the 1st line of it (removing it from the art)
                        └ order the stack to [remaining, "@¶|¶|..", currentLine]
                        l get the length of the current line
                        2M max of that and 2
                        2% that % 2
                        ±├ (-that) + 2
                        ×× prepend (-max(len,2)%2) + 2 spaces
                        l get the length of the new string
                        ⇵╷ ceil(len / 2) -1
                        -× repeat "-" that many times - half of the podiums top
                        └ order stack to [art, currLine, "@¶|¶|..", "----"]
                        + append the dashes to the vertical bar = "@-----¶|¶|.."
                        -α∔ vertically add "-" and the original vertical bar - "-¶@¶|¶|.."
                        k remove the last line of that to make up for the middles shortness
                        + and append that horizontally - half of the podium without the name
                        │ palindromize the podium
                        ∔ and prepend the name
                        ⇵ reverse vertically so the outputs could be aligned to the bottom
                        ; and get the rest of the centered input on top
                        Finally,
                        ┐ remove the useless now-empty input
                        ++ join the 3 podium parts together
                        ⇵ and undo the reversing


                        Abuses "and it doesn't need to be consistent", making it pretty unintelligible.






                        share|improve this answer











                        $endgroup$













                        • $begingroup$
                          Umm...any chance of an explanation?
                          $endgroup$
                          – Matias Bjarland
                          2 hours ago










                        • $begingroup$
                          @MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
                          $endgroup$
                          – dzaima
                          2 hours ago
















                        0












                        $begingroup$


                        Canvas, 45 bytes



                        r351⁰{|*@;∔;J└l2M2%±├ ××l⇵╷-×└+-α∔k+│∔⇵;}┐++⇵


                        Try it here!



                        Explanation:



                        r    Center the input, preferring left. Converts to an ASCII-art object
                        which pads everything with spaces. This is the bulk of the magic.

                        251⁰{ .... } for each number in [2, 5, 1]:
                        |* repeat "|" vertically that many times
                        @;∔ prepend an "@" - a vertical bar for later
                        ; swap top 2 stack items - put the centered art on top
                        J push the 1st line of it (removing it from the art)
                        └ order the stack to [remaining, "@¶|¶|..", currentLine]
                        l get the length of the current line
                        2M max of that and 2
                        2% that % 2
                        ±├ (-that) + 2
                        ×× prepend (-max(len,2)%2) + 2 spaces
                        l get the length of the new string
                        ⇵╷ ceil(len / 2) -1
                        -× repeat "-" that many times - half of the podiums top
                        └ order stack to [art, currLine, "@¶|¶|..", "----"]
                        + append the dashes to the vertical bar = "@-----¶|¶|.."
                        -α∔ vertically add "-" and the original vertical bar - "-¶@¶|¶|.."
                        k remove the last line of that to make up for the middles shortness
                        + and append that horizontally - half of the podium without the name
                        │ palindromize the podium
                        ∔ and prepend the name
                        ⇵ reverse vertically so the outputs could be aligned to the bottom
                        ; and get the rest of the centered input on top
                        Finally,
                        ┐ remove the useless now-empty input
                        ++ join the 3 podium parts together
                        ⇵ and undo the reversing


                        Abuses "and it doesn't need to be consistent", making it pretty unintelligible.






                        share|improve this answer











                        $endgroup$













                        • $begingroup$
                          Umm...any chance of an explanation?
                          $endgroup$
                          – Matias Bjarland
                          2 hours ago










                        • $begingroup$
                          @MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
                          $endgroup$
                          – dzaima
                          2 hours ago














                        0












                        0








                        0





                        $begingroup$


                        Canvas, 45 bytes



                        r351⁰{|*@;∔;J└l2M2%±├ ××l⇵╷-×└+-α∔k+│∔⇵;}┐++⇵


                        Try it here!



                        Explanation:



                        r    Center the input, preferring left. Converts to an ASCII-art object
                        which pads everything with spaces. This is the bulk of the magic.

                        251⁰{ .... } for each number in [2, 5, 1]:
                        |* repeat "|" vertically that many times
                        @;∔ prepend an "@" - a vertical bar for later
                        ; swap top 2 stack items - put the centered art on top
                        J push the 1st line of it (removing it from the art)
                        └ order the stack to [remaining, "@¶|¶|..", currentLine]
                        l get the length of the current line
                        2M max of that and 2
                        2% that % 2
                        ±├ (-that) + 2
                        ×× prepend (-max(len,2)%2) + 2 spaces
                        l get the length of the new string
                        ⇵╷ ceil(len / 2) -1
                        -× repeat "-" that many times - half of the podiums top
                        └ order stack to [art, currLine, "@¶|¶|..", "----"]
                        + append the dashes to the vertical bar = "@-----¶|¶|.."
                        -α∔ vertically add "-" and the original vertical bar - "-¶@¶|¶|.."
                        k remove the last line of that to make up for the middles shortness
                        + and append that horizontally - half of the podium without the name
                        │ palindromize the podium
                        ∔ and prepend the name
                        ⇵ reverse vertically so the outputs could be aligned to the bottom
                        ; and get the rest of the centered input on top
                        Finally,
                        ┐ remove the useless now-empty input
                        ++ join the 3 podium parts together
                        ⇵ and undo the reversing


                        Abuses "and it doesn't need to be consistent", making it pretty unintelligible.






                        share|improve this answer











                        $endgroup$




                        Canvas, 45 bytes



                        r351⁰{|*@;∔;J└l2M2%±├ ××l⇵╷-×└+-α∔k+│∔⇵;}┐++⇵


                        Try it here!



                        Explanation:



                        r    Center the input, preferring left. Converts to an ASCII-art object
                        which pads everything with spaces. This is the bulk of the magic.

                        251⁰{ .... } for each number in [2, 5, 1]:
                        |* repeat "|" vertically that many times
                        @;∔ prepend an "@" - a vertical bar for later
                        ; swap top 2 stack items - put the centered art on top
                        J push the 1st line of it (removing it from the art)
                        └ order the stack to [remaining, "@¶|¶|..", currentLine]
                        l get the length of the current line
                        2M max of that and 2
                        2% that % 2
                        ±├ (-that) + 2
                        ×× prepend (-max(len,2)%2) + 2 spaces
                        l get the length of the new string
                        ⇵╷ ceil(len / 2) -1
                        -× repeat "-" that many times - half of the podiums top
                        └ order stack to [art, currLine, "@¶|¶|..", "----"]
                        + append the dashes to the vertical bar = "@-----¶|¶|.."
                        -α∔ vertically add "-" and the original vertical bar - "-¶@¶|¶|.."
                        k remove the last line of that to make up for the middles shortness
                        + and append that horizontally - half of the podium without the name
                        │ palindromize the podium
                        ∔ and prepend the name
                        ⇵ reverse vertically so the outputs could be aligned to the bottom
                        ; and get the rest of the centered input on top
                        Finally,
                        ┐ remove the useless now-empty input
                        ++ join the 3 podium parts together
                        ⇵ and undo the reversing


                        Abuses "and it doesn't need to be consistent", making it pretty unintelligible.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited 2 hours ago

























                        answered 7 hours ago









                        dzaimadzaima

                        15.1k21856




                        15.1k21856












                        • $begingroup$
                          Umm...any chance of an explanation?
                          $endgroup$
                          – Matias Bjarland
                          2 hours ago










                        • $begingroup$
                          @MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
                          $endgroup$
                          – dzaima
                          2 hours ago


















                        • $begingroup$
                          Umm...any chance of an explanation?
                          $endgroup$
                          – Matias Bjarland
                          2 hours ago










                        • $begingroup$
                          @MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
                          $endgroup$
                          – dzaima
                          2 hours ago
















                        $begingroup$
                        Umm...any chance of an explanation?
                        $endgroup$
                        – Matias Bjarland
                        2 hours ago




                        $begingroup$
                        Umm...any chance of an explanation?
                        $endgroup$
                        – Matias Bjarland
                        2 hours ago












                        $begingroup$
                        @MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
                        $endgroup$
                        – dzaima
                        2 hours ago




                        $begingroup$
                        @MatiasBjarland though it's mostly stack manipulation and the rest i barely understand, there.
                        $endgroup$
                        – dzaima
                        2 hours ago











                        0












                        $begingroup$


                        Charcoal, 63 bytes



                        ≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⟧≔⁻⁷ⅉιP↓ι@ηP↓ιP↓@@¹ηP↓ι@


                        Try it online! Link is to verbose version of code. Explanation:



                        ≔÷⌈EθLι²η


                        Calculate the number of spaces in each half of a podium.



                        F³«


                        Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.



                        J×ι⁺³⊗η⊗﹪⁻¹ι³


                        Position to the start of the line that will have the text.



                        ⟦◧§θι⁺⊕η⊘⊕L§θι⟧


                        Output the text with enough left padding to centre it.



                        ≔⁻⁷ⅉι


                        Get the height of the podium.



                        P↓ι@ηP↓ιP↓@@¹ηP↓ι@


                        Draw the podium.



                        Alternative approach, also 63 bytes:



                        ≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⪫@-@×-η⟧E⁻⁷ⅉ⪫⪫||§|@¬κ× η


                        Try it online! Link is to verbose version of code. Explanation:



                        ≔÷⌈EθLι²η


                        Calculate the number of spaces in each half of a podium.



                        F³«


                        Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.



                        J×ι⁺³⊗η⊗﹪⁻¹ι³


                        Position to the start of the line that will have the text.



                        ⟦◧§θι⁺⊕η⊘⊕L§θι


                        Output the text with enough left padding to centre it.



                        ⪫@-@×-η⟧


                        Also output the top of the podium by inserting -s between the characters of the string @-@ to reach the correct width.



                        E⁻⁷ⅉ⪫⪫||§|@¬κ× η


                        Print the remainder of the podium by spacing the |s appropriately, except that the middle character is a @ on the first row.






                        share|improve this answer









                        $endgroup$


















                          0












                          $begingroup$


                          Charcoal, 63 bytes



                          ≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⟧≔⁻⁷ⅉιP↓ι@ηP↓ιP↓@@¹ηP↓ι@


                          Try it online! Link is to verbose version of code. Explanation:



                          ≔÷⌈EθLι²η


                          Calculate the number of spaces in each half of a podium.



                          F³«


                          Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.



                          J×ι⁺³⊗η⊗﹪⁻¹ι³


                          Position to the start of the line that will have the text.



                          ⟦◧§θι⁺⊕η⊘⊕L§θι⟧


                          Output the text with enough left padding to centre it.



                          ≔⁻⁷ⅉι


                          Get the height of the podium.



                          P↓ι@ηP↓ιP↓@@¹ηP↓ι@


                          Draw the podium.



                          Alternative approach, also 63 bytes:



                          ≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⪫@-@×-η⟧E⁻⁷ⅉ⪫⪫||§|@¬κ× η


                          Try it online! Link is to verbose version of code. Explanation:



                          ≔÷⌈EθLι²η


                          Calculate the number of spaces in each half of a podium.



                          F³«


                          Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.



                          J×ι⁺³⊗η⊗﹪⁻¹ι³


                          Position to the start of the line that will have the text.



                          ⟦◧§θι⁺⊕η⊘⊕L§θι


                          Output the text with enough left padding to centre it.



                          ⪫@-@×-η⟧


                          Also output the top of the podium by inserting -s between the characters of the string @-@ to reach the correct width.



                          E⁻⁷ⅉ⪫⪫||§|@¬κ× η


                          Print the remainder of the podium by spacing the |s appropriately, except that the middle character is a @ on the first row.






                          share|improve this answer









                          $endgroup$
















                            0












                            0








                            0





                            $begingroup$


                            Charcoal, 63 bytes



                            ≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⟧≔⁻⁷ⅉιP↓ι@ηP↓ιP↓@@¹ηP↓ι@


                            Try it online! Link is to verbose version of code. Explanation:



                            ≔÷⌈EθLι²η


                            Calculate the number of spaces in each half of a podium.



                            F³«


                            Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.



                            J×ι⁺³⊗η⊗﹪⁻¹ι³


                            Position to the start of the line that will have the text.



                            ⟦◧§θι⁺⊕η⊘⊕L§θι⟧


                            Output the text with enough left padding to centre it.



                            ≔⁻⁷ⅉι


                            Get the height of the podium.



                            P↓ι@ηP↓ιP↓@@¹ηP↓ι@


                            Draw the podium.



                            Alternative approach, also 63 bytes:



                            ≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⪫@-@×-η⟧E⁻⁷ⅉ⪫⪫||§|@¬κ× η


                            Try it online! Link is to verbose version of code. Explanation:



                            ≔÷⌈EθLι²η


                            Calculate the number of spaces in each half of a podium.



                            F³«


                            Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.



                            J×ι⁺³⊗η⊗﹪⁻¹ι³


                            Position to the start of the line that will have the text.



                            ⟦◧§θι⁺⊕η⊘⊕L§θι


                            Output the text with enough left padding to centre it.



                            ⪫@-@×-η⟧


                            Also output the top of the podium by inserting -s between the characters of the string @-@ to reach the correct width.



                            E⁻⁷ⅉ⪫⪫||§|@¬κ× η


                            Print the remainder of the podium by spacing the |s appropriately, except that the middle character is a @ on the first row.






                            share|improve this answer









                            $endgroup$




                            Charcoal, 63 bytes



                            ≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⟧≔⁻⁷ⅉιP↓ι@ηP↓ιP↓@@¹ηP↓ι@


                            Try it online! Link is to verbose version of code. Explanation:



                            ≔÷⌈EθLι²η


                            Calculate the number of spaces in each half of a podium.



                            F³«


                            Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.



                            J×ι⁺³⊗η⊗﹪⁻¹ι³


                            Position to the start of the line that will have the text.



                            ⟦◧§θι⁺⊕η⊘⊕L§θι⟧


                            Output the text with enough left padding to centre it.



                            ≔⁻⁷ⅉι


                            Get the height of the podium.



                            P↓ι@ηP↓ιP↓@@¹ηP↓ι@


                            Draw the podium.



                            Alternative approach, also 63 bytes:



                            ≔÷⌈EθLι²ηF³«J×ι⁺³⊗η⊗﹪⁻¹ι³⟦◧§θι⁺⊕η⊘⊕L§θι⪫@-@×-η⟧E⁻⁷ⅉ⪫⪫||§|@¬κ× η


                            Try it online! Link is to verbose version of code. Explanation:



                            ≔÷⌈EθLι²η


                            Calculate the number of spaces in each half of a podium.



                            F³«


                            Loop over each place. Note that input is expected to be in the order 2nd, 1st, 3rd.



                            J×ι⁺³⊗η⊗﹪⁻¹ι³


                            Position to the start of the line that will have the text.



                            ⟦◧§θι⁺⊕η⊘⊕L§θι


                            Output the text with enough left padding to centre it.



                            ⪫@-@×-η⟧


                            Also output the top of the podium by inserting -s between the characters of the string @-@ to reach the correct width.



                            E⁻⁷ⅉ⪫⪫||§|@¬κ× η


                            Print the remainder of the podium by spacing the |s appropriately, except that the middle character is a @ on the first row.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 52 mins ago









                            NeilNeil

                            80.8k744178




                            80.8k744178






























                                draft saved

                                draft discarded




















































                                If this is an answer to a challenge…




                                • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                  Explanations of your answer make it more interesting to read and are very much encouraged.


                                • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                More generally…




                                • …Please make sure to answer the question and provide sufficient detail.


                                • …Avoid asking for help, clarification or responding to other answers (use comments instead).





                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f180187%2fbuild-ascii-podiums%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Mouse cursor on multiple screens with different PPI

                                Agildo Ribeiro

                                Sometime when accessing a menu: “Ubuntu 16.04 has experienced an internal error”