Expand a hexagon





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







23












$begingroup$


Given an ASCII art hexagon as input, output one whose sides are all one unit longer.



                     _____
____ /
/ /
/ /
=>
/ /
____/ /
_____/


The input hexagons will have 180 degree symmetry, but otherwise the sides can be all different lengths. Above, the side lengths (2, 4, 3) get enlarged to (3, 5, 4). The side lengths will be nonzero.



The hexagons are made of underscores _, slashes /, and backslashes . Note that of the horizontal edges (made with underscores), the top edge is on its own line but the bottom edge is not.



I/O



I'm going to be a stickler and require ascii-art formatting here: the input and output should be a string with newlines representing the image, not a list of lines. Of course, your code may print each line in turn to produce the image, or read STDIN a line a time for input if your language can do that.



Details



The input may include an optional trailing newline if you wish, but will otherwise have no empty lines. You can choose to either have no trailing spaces in the input, or spaces to pad each line to the same length (that of the longest line).



The output should be flush with the left edge of the screen, like the input. You may have extra newlines above and below as well as trailing spaces.



Test cases



Input followed by output.



 _
/
_/

__
/
/
/
__/




  ____
/
/

/
____/

_____
/
/
/

/
/
_____/




     _
/
/ /
/ /
/ /
/ /
_/

__
/
/
/ /
/ /
/ /
/ /
/
__/


Leaderboard






<iframe src="https://xmikee1.github.io/ppcg-leaderboard/?id=185760" width="100%" height="100%" style="border: none;">Oops, your browser is too old to view this content! Please upgrade to a newer version of your browser that supports HTML5.</iframe><style>html,body{margin:0;padding:0;height:100%;overflow:hidden}</style>












share|improve this question











$endgroup$












  • $begingroup$
    Must the output hexagon be the same one but bigger, or can it be any hexagon with the appropriate side lengths?
    $endgroup$
    – Stephen
    May 18 at 2:47






  • 1




    $begingroup$
    @Stephen It must be the same one but bigger, in the same orientation.
    $endgroup$
    – xnor
    May 18 at 2:48








  • 2




    $begingroup$
    This is a great example of a really well written challenge. Short, clear and to the point. May I make a small suggestion? "Stickler" may not be clear for all non native English speakers. May I suggest that "I will only accept..." or something similar may be easier to understand? +1 anyway.
    $endgroup$
    – ElPedro
    May 18 at 20:43












  • $begingroup$
    Can we return an array/IEnumerable of characters?
    $endgroup$
    – Embodiment of Ignorance
    May 19 at 1:23












  • $begingroup$
    @EmbodimentofIgnorance Yes, those are fine, as long as the have the required newline characters.
    $endgroup$
    – xnor
    May 19 at 3:06


















23












$begingroup$


Given an ASCII art hexagon as input, output one whose sides are all one unit longer.



                     _____
____ /
/ /
/ /
=>
/ /
____/ /
_____/


The input hexagons will have 180 degree symmetry, but otherwise the sides can be all different lengths. Above, the side lengths (2, 4, 3) get enlarged to (3, 5, 4). The side lengths will be nonzero.



The hexagons are made of underscores _, slashes /, and backslashes . Note that of the horizontal edges (made with underscores), the top edge is on its own line but the bottom edge is not.



I/O



I'm going to be a stickler and require ascii-art formatting here: the input and output should be a string with newlines representing the image, not a list of lines. Of course, your code may print each line in turn to produce the image, or read STDIN a line a time for input if your language can do that.



Details



The input may include an optional trailing newline if you wish, but will otherwise have no empty lines. You can choose to either have no trailing spaces in the input, or spaces to pad each line to the same length (that of the longest line).



The output should be flush with the left edge of the screen, like the input. You may have extra newlines above and below as well as trailing spaces.



Test cases



Input followed by output.



 _
/
_/

__
/
/
/
__/




  ____
/
/

/
____/

_____
/
/
/

/
/
_____/




     _
/
/ /
/ /
/ /
/ /
_/

__
/
/
/ /
/ /
/ /
/ /
/
__/


Leaderboard






<iframe src="https://xmikee1.github.io/ppcg-leaderboard/?id=185760" width="100%" height="100%" style="border: none;">Oops, your browser is too old to view this content! Please upgrade to a newer version of your browser that supports HTML5.</iframe><style>html,body{margin:0;padding:0;height:100%;overflow:hidden}</style>












share|improve this question











$endgroup$












  • $begingroup$
    Must the output hexagon be the same one but bigger, or can it be any hexagon with the appropriate side lengths?
    $endgroup$
    – Stephen
    May 18 at 2:47






  • 1




    $begingroup$
    @Stephen It must be the same one but bigger, in the same orientation.
    $endgroup$
    – xnor
    May 18 at 2:48








  • 2




    $begingroup$
    This is a great example of a really well written challenge. Short, clear and to the point. May I make a small suggestion? "Stickler" may not be clear for all non native English speakers. May I suggest that "I will only accept..." or something similar may be easier to understand? +1 anyway.
    $endgroup$
    – ElPedro
    May 18 at 20:43












  • $begingroup$
    Can we return an array/IEnumerable of characters?
    $endgroup$
    – Embodiment of Ignorance
    May 19 at 1:23












  • $begingroup$
    @EmbodimentofIgnorance Yes, those are fine, as long as the have the required newline characters.
    $endgroup$
    – xnor
    May 19 at 3:06














23












23








23


1



$begingroup$


Given an ASCII art hexagon as input, output one whose sides are all one unit longer.



                     _____
____ /
/ /
/ /
=>
/ /
____/ /
_____/


The input hexagons will have 180 degree symmetry, but otherwise the sides can be all different lengths. Above, the side lengths (2, 4, 3) get enlarged to (3, 5, 4). The side lengths will be nonzero.



The hexagons are made of underscores _, slashes /, and backslashes . Note that of the horizontal edges (made with underscores), the top edge is on its own line but the bottom edge is not.



I/O



I'm going to be a stickler and require ascii-art formatting here: the input and output should be a string with newlines representing the image, not a list of lines. Of course, your code may print each line in turn to produce the image, or read STDIN a line a time for input if your language can do that.



Details



The input may include an optional trailing newline if you wish, but will otherwise have no empty lines. You can choose to either have no trailing spaces in the input, or spaces to pad each line to the same length (that of the longest line).



The output should be flush with the left edge of the screen, like the input. You may have extra newlines above and below as well as trailing spaces.



Test cases



Input followed by output.



 _
/
_/

__
/
/
/
__/




  ____
/
/

/
____/

_____
/
/
/

/
/
_____/




     _
/
/ /
/ /
/ /
/ /
_/

__
/
/
/ /
/ /
/ /
/ /
/
__/


Leaderboard






<iframe src="https://xmikee1.github.io/ppcg-leaderboard/?id=185760" width="100%" height="100%" style="border: none;">Oops, your browser is too old to view this content! Please upgrade to a newer version of your browser that supports HTML5.</iframe><style>html,body{margin:0;padding:0;height:100%;overflow:hidden}</style>












share|improve this question











$endgroup$




Given an ASCII art hexagon as input, output one whose sides are all one unit longer.



                     _____
____ /
/ /
/ /
=>
/ /
____/ /
_____/


The input hexagons will have 180 degree symmetry, but otherwise the sides can be all different lengths. Above, the side lengths (2, 4, 3) get enlarged to (3, 5, 4). The side lengths will be nonzero.



The hexagons are made of underscores _, slashes /, and backslashes . Note that of the horizontal edges (made with underscores), the top edge is on its own line but the bottom edge is not.



I/O



I'm going to be a stickler and require ascii-art formatting here: the input and output should be a string with newlines representing the image, not a list of lines. Of course, your code may print each line in turn to produce the image, or read STDIN a line a time for input if your language can do that.



Details



The input may include an optional trailing newline if you wish, but will otherwise have no empty lines. You can choose to either have no trailing spaces in the input, or spaces to pad each line to the same length (that of the longest line).



The output should be flush with the left edge of the screen, like the input. You may have extra newlines above and below as well as trailing spaces.



Test cases



Input followed by output.



 _
/
_/

__
/
/
/
__/




  ____
/
/

/
____/

_____
/
/
/

/
/
_____/




     _
/
/ /
/ /
/ /
/ /
_/

__
/
/
/ /
/ /
/ /
/ /
/
__/


Leaderboard






<iframe src="https://xmikee1.github.io/ppcg-leaderboard/?id=185760" width="100%" height="100%" style="border: none;">Oops, your browser is too old to view this content! Please upgrade to a newer version of your browser that supports HTML5.</iframe><style>html,body{margin:0;padding:0;height:100%;overflow:hidden}</style>








<iframe src="https://xmikee1.github.io/ppcg-leaderboard/?id=185760" width="100%" height="100%" style="border: none;">Oops, your browser is too old to view this content! Please upgrade to a newer version of your browser that supports HTML5.</iframe><style>html,body{margin:0;padding:0;height:100%;overflow:hidden}</style>





<iframe src="https://xmikee1.github.io/ppcg-leaderboard/?id=185760" width="100%" height="100%" style="border: none;">Oops, your browser is too old to view this content! Please upgrade to a newer version of your browser that supports HTML5.</iframe><style>html,body{margin:0;padding:0;height:100%;overflow:hidden}</style>






code-golf ascii-art geometry






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 19 at 1:03







xnor

















asked May 18 at 2:13









xnorxnor

97.2k19 gold badges200 silver badges460 bronze badges




97.2k19 gold badges200 silver badges460 bronze badges












  • $begingroup$
    Must the output hexagon be the same one but bigger, or can it be any hexagon with the appropriate side lengths?
    $endgroup$
    – Stephen
    May 18 at 2:47






  • 1




    $begingroup$
    @Stephen It must be the same one but bigger, in the same orientation.
    $endgroup$
    – xnor
    May 18 at 2:48








  • 2




    $begingroup$
    This is a great example of a really well written challenge. Short, clear and to the point. May I make a small suggestion? "Stickler" may not be clear for all non native English speakers. May I suggest that "I will only accept..." or something similar may be easier to understand? +1 anyway.
    $endgroup$
    – ElPedro
    May 18 at 20:43












  • $begingroup$
    Can we return an array/IEnumerable of characters?
    $endgroup$
    – Embodiment of Ignorance
    May 19 at 1:23












  • $begingroup$
    @EmbodimentofIgnorance Yes, those are fine, as long as the have the required newline characters.
    $endgroup$
    – xnor
    May 19 at 3:06


















  • $begingroup$
    Must the output hexagon be the same one but bigger, or can it be any hexagon with the appropriate side lengths?
    $endgroup$
    – Stephen
    May 18 at 2:47






  • 1




    $begingroup$
    @Stephen It must be the same one but bigger, in the same orientation.
    $endgroup$
    – xnor
    May 18 at 2:48








  • 2




    $begingroup$
    This is a great example of a really well written challenge. Short, clear and to the point. May I make a small suggestion? "Stickler" may not be clear for all non native English speakers. May I suggest that "I will only accept..." or something similar may be easier to understand? +1 anyway.
    $endgroup$
    – ElPedro
    May 18 at 20:43












  • $begingroup$
    Can we return an array/IEnumerable of characters?
    $endgroup$
    – Embodiment of Ignorance
    May 19 at 1:23












  • $begingroup$
    @EmbodimentofIgnorance Yes, those are fine, as long as the have the required newline characters.
    $endgroup$
    – xnor
    May 19 at 3:06
















$begingroup$
Must the output hexagon be the same one but bigger, or can it be any hexagon with the appropriate side lengths?
$endgroup$
– Stephen
May 18 at 2:47




$begingroup$
Must the output hexagon be the same one but bigger, or can it be any hexagon with the appropriate side lengths?
$endgroup$
– Stephen
May 18 at 2:47




1




1




$begingroup$
@Stephen It must be the same one but bigger, in the same orientation.
$endgroup$
– xnor
May 18 at 2:48






$begingroup$
@Stephen It must be the same one but bigger, in the same orientation.
$endgroup$
– xnor
May 18 at 2:48






2




2




$begingroup$
This is a great example of a really well written challenge. Short, clear and to the point. May I make a small suggestion? "Stickler" may not be clear for all non native English speakers. May I suggest that "I will only accept..." or something similar may be easier to understand? +1 anyway.
$endgroup$
– ElPedro
May 18 at 20:43






$begingroup$
This is a great example of a really well written challenge. Short, clear and to the point. May I make a small suggestion? "Stickler" may not be clear for all non native English speakers. May I suggest that "I will only accept..." or something similar may be easier to understand? +1 anyway.
$endgroup$
– ElPedro
May 18 at 20:43














$begingroup$
Can we return an array/IEnumerable of characters?
$endgroup$
– Embodiment of Ignorance
May 19 at 1:23






$begingroup$
Can we return an array/IEnumerable of characters?
$endgroup$
– Embodiment of Ignorance
May 19 at 1:23














$begingroup$
@EmbodimentofIgnorance Yes, those are fine, as long as the have the required newline characters.
$endgroup$
– xnor
May 19 at 3:06




$begingroup$
@EmbodimentofIgnorance Yes, those are fine, as long as the have the required newline characters.
$endgroup$
– xnor
May 19 at 3:06










6 Answers
6






active

oldest

votes


















6












$begingroup$


Stax, 28 bytes



╙Σ■♀♪«G[▀[TÖe╟╗ê'○▀ÄT→│╧(╡¢╩


Run and debug it



Seems like there should be a way to do it mostly with regex, but I'm still looking...






share|improve this answer









$endgroup$





















    5












    $begingroup$


    Retina 0.8.2, 84 bytes



    m`(¶.*)( .)$
    $1 $2
    (_+¶)(( */) ( *.))
    _$1 $3$4¶$2
    ( *.)(_+/)$
    $1$.2$* /¶ $1_$2


    Try it online! Works with irregular hexagons. I/O is unpadded. Explanation:



    m`(¶.*)( .)$
    $1 $2


    Widen the interior of the hexagon.



    (_+¶)(( */)  ( *.))
    _$1 $3$4¶$2


    Fix up the top.



    ( *.)(_+/)$
    $1$.2$* /¶ $1_$2


    Fix up the bottom.






    share|improve this answer









    $endgroup$





















      5












      $begingroup$

      JavaScript (ES6),  159 156 153  150 bytes





      s=>s[r='replace'](/S /g,'$&   ')[r](/.*/,s=>s[r](e=/_+/,` $&_
      `+s[r](e,'/$& \')[r](e=/_/g,' ')))[r](/ *\_+/,s=>s[r](e,' ')+` /
      `+s[r](/_/,'__'))


      Try it online!



      Commented



      NB: Alternate characters are used below for the regex delimiters to prevent SE syntax highlighter from going berserk.



      s =>                       // s = input
      s[r = 'replace']( // r = alias for 'replace'
      // STEP #1
      ∕S ∕g, // insert two middle spaces for all lines
      '$& ' // that contain a border, followed by a space
      ) // (i.e. all lines except the first and the last one)
      [r]( // STEP #2
      ∕.*∕, // isolate the first line
      s => // let s be this first line
      s[r]( //
      e = ∕_+∕, // find the sequence of underscores and replace it with:
      ` $&_n` + // the same sequence preceded by a space and followed by '_'
      s[r]( // followed by a linefeed and:
      e, // the same sequence preceded by '/' and followed by ' '
      '/$& \' //
      ) // with:
      [r](e = ∕_∕g, ' ') // all underscores replaced with spaces
      )) //
      [r]( // STEP #3
      ∕ *\_+∕, // isolate the last line, without the trailing '/'
      s => // let s be this last line
      s[r](e, ' ') + // replace all underscores with spaces
      ` /n ` + // append 3 spaces and a trailing '/', followed by a linefeed
      s[r](∕_∕, '__') // append s with an extra underscore
      ) //





      share|improve this answer











      $endgroup$





















        2












        $begingroup$


        Charcoal, 48 bytes



        SθW¬№ω_≔⁺ωSω≔⊕⊘№ωη≔⊕⊘№ω/ζ≔×_⊕№ω_θ↗ζθ↓↘η←↙ζ↑←θ↖η


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



        SθW¬№ω_≔⁺ωSω


        Input and concatenate all of the lines except the first. (Input in JSON format would make most of this unnecessary at a saving of 11 bytes.)



        ≔⊕⊘№ωη≔⊕⊘№ω/ζ≔×_⊕№ω_θ


        Count the number of /s, /s, and _s in the string and use that to calculate the new side lengths (in the case of _s, as a string of _s of that length).



        ↗ζθ↓↘η←↙ζ↑←θ↖η


        Draw the enlarged hexagon.



        Alternative solution, also 48 bytes:



        SθW¬№ω_≔⁺ωSω≔⁺θωθF²«≔E/_⊕⊘№θκη×_⊟ηM⁰¬ιFη«↷¹κ↷¹¶


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



        SθW¬№ω_≔⁺ωSω≔⁺θωθ


        Input all of the lines. (Input in JSON format would make this unnecessary at a saving of 17 bytes.)



        F²«


        Draw the top right and bottom left sections of the hexagon separately.



        ≔E/_⊕⊘№θκ


        Count the number of /s, /s, and _s in the string and use that to calculate the new side lengths.



        η×_⊟ηM⁰¬ι


        Output the top or bottom, and move down a line if this was the top line.



        Fη«↷¹κ↷¹¶


        Draw both of the right or left sides.






        share|improve this answer









        $endgroup$





















          2












          $begingroup$


          APL (Dyalog Unicode), 75 74 bytesSBCS





          ' /_'∘{⍺[a×1=(+⍀×a)⌊⊖+⍀⊖×a←2⌈/{⊃0~⍨1⌷⍵,⍨⍉⍵}⌺3 3(0,0,⍨⍉)⍣3⍉⍺⍳↑⍵]}'.+'⎕s'&'


          Try it online!



          '.+'⎕s'&' split input into lines



          ↑⍵ mix lines into a matrix



          ⍺⍳ replace ' /_' with 0 1 2 3



          (0,0,⍨⍉)⍣3⍉ surround with a layer of 0s on top&bottom and two layers of 0s on the left&right



          {⊃0~⍨1⌷⍵,⍨⍉⍵}⌺3 3 for each cell choose the first non-0 from: upper, lower, left, right from the 3x3 neighbourhood centred on it



          2⌈/ max in pairs horizontally



          a×1=(+⍀×a)⌊⊖+⍀⊖×a← keep only the outer boundary of non-0s



          ⍺[ ] replace 0 1 2 3 with ' /_'






          share|improve this answer











          $endgroup$





















            0












            $begingroup$


            Perl 5, 177 156 145 bytes





            @l=pop=~/.+/g;splice@l,$_,0,$l[$_]=~s,_, ,gr for-1,1;$l[$_]=~s, (S)( +)(S),$_<2?" $1$2 $3":"$1$2   $3",e for 1..@l-2;join("n",@l)=~s,_+,$&_,gr


            Could be shorter? Don't see how just yet. With comments and added newlines and header+footer:



            sub f {
            @l=pop=~/.+/g; #1
            splice@l,$_,0,$l[$_]=~s,_, ,gr for-1,1; #2
            $l[$_]=~s, (S)( +)(S),$_<2?" $1$2 $3":"$1$2 $3",e for 1..@l-2; #3
            join("n",@l)=~s,_+,$&_,gr #4
            }


            Try it online!



            Line #1 splits multi-line input string into the @l array.



            Line #2 duplicates second and last lines without the _ chars.



            Line #3 adds spaces where needed on line 2 to second last.



            Line #4 widens the two ___ sides with one _ and returns the @l array of lines as one multi-line string.






            share|improve this answer











            $endgroup$
















              Your Answer






              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%2f185760%2fexpand-a-hexagon%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              6 Answers
              6






              active

              oldest

              votes








              6 Answers
              6






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              6












              $begingroup$


              Stax, 28 bytes



              ╙Σ■♀♪«G[▀[TÖe╟╗ê'○▀ÄT→│╧(╡¢╩


              Run and debug it



              Seems like there should be a way to do it mostly with regex, but I'm still looking...






              share|improve this answer









              $endgroup$


















                6












                $begingroup$


                Stax, 28 bytes



                ╙Σ■♀♪«G[▀[TÖe╟╗ê'○▀ÄT→│╧(╡¢╩


                Run and debug it



                Seems like there should be a way to do it mostly with regex, but I'm still looking...






                share|improve this answer









                $endgroup$
















                  6












                  6








                  6





                  $begingroup$


                  Stax, 28 bytes



                  ╙Σ■♀♪«G[▀[TÖe╟╗ê'○▀ÄT→│╧(╡¢╩


                  Run and debug it



                  Seems like there should be a way to do it mostly with regex, but I'm still looking...






                  share|improve this answer









                  $endgroup$




                  Stax, 28 bytes



                  ╙Σ■♀♪«G[▀[TÖe╟╗ê'○▀ÄT→│╧(╡¢╩


                  Run and debug it



                  Seems like there should be a way to do it mostly with regex, but I'm still looking...







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 18 at 6:27









                  recursiverecursive

                  7,18814 silver badges30 bronze badges




                  7,18814 silver badges30 bronze badges

























                      5












                      $begingroup$


                      Retina 0.8.2, 84 bytes



                      m`(¶.*)( .)$
                      $1 $2
                      (_+¶)(( */) ( *.))
                      _$1 $3$4¶$2
                      ( *.)(_+/)$
                      $1$.2$* /¶ $1_$2


                      Try it online! Works with irregular hexagons. I/O is unpadded. Explanation:



                      m`(¶.*)( .)$
                      $1 $2


                      Widen the interior of the hexagon.



                      (_+¶)(( */)  ( *.))
                      _$1 $3$4¶$2


                      Fix up the top.



                      ( *.)(_+/)$
                      $1$.2$* /¶ $1_$2


                      Fix up the bottom.






                      share|improve this answer









                      $endgroup$


















                        5












                        $begingroup$


                        Retina 0.8.2, 84 bytes



                        m`(¶.*)( .)$
                        $1 $2
                        (_+¶)(( */) ( *.))
                        _$1 $3$4¶$2
                        ( *.)(_+/)$
                        $1$.2$* /¶ $1_$2


                        Try it online! Works with irregular hexagons. I/O is unpadded. Explanation:



                        m`(¶.*)( .)$
                        $1 $2


                        Widen the interior of the hexagon.



                        (_+¶)(( */)  ( *.))
                        _$1 $3$4¶$2


                        Fix up the top.



                        ( *.)(_+/)$
                        $1$.2$* /¶ $1_$2


                        Fix up the bottom.






                        share|improve this answer









                        $endgroup$
















                          5












                          5








                          5





                          $begingroup$


                          Retina 0.8.2, 84 bytes



                          m`(¶.*)( .)$
                          $1 $2
                          (_+¶)(( */) ( *.))
                          _$1 $3$4¶$2
                          ( *.)(_+/)$
                          $1$.2$* /¶ $1_$2


                          Try it online! Works with irregular hexagons. I/O is unpadded. Explanation:



                          m`(¶.*)( .)$
                          $1 $2


                          Widen the interior of the hexagon.



                          (_+¶)(( */)  ( *.))
                          _$1 $3$4¶$2


                          Fix up the top.



                          ( *.)(_+/)$
                          $1$.2$* /¶ $1_$2


                          Fix up the bottom.






                          share|improve this answer









                          $endgroup$




                          Retina 0.8.2, 84 bytes



                          m`(¶.*)( .)$
                          $1 $2
                          (_+¶)(( */) ( *.))
                          _$1 $3$4¶$2
                          ( *.)(_+/)$
                          $1$.2$* /¶ $1_$2


                          Try it online! Works with irregular hexagons. I/O is unpadded. Explanation:



                          m`(¶.*)( .)$
                          $1 $2


                          Widen the interior of the hexagon.



                          (_+¶)(( */)  ( *.))
                          _$1 $3$4¶$2


                          Fix up the top.



                          ( *.)(_+/)$
                          $1$.2$* /¶ $1_$2


                          Fix up the bottom.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered May 18 at 11:47









                          NeilNeil

                          86.2k8 gold badges46 silver badges183 bronze badges




                          86.2k8 gold badges46 silver badges183 bronze badges























                              5












                              $begingroup$

                              JavaScript (ES6),  159 156 153  150 bytes





                              s=>s[r='replace'](/S /g,'$&   ')[r](/.*/,s=>s[r](e=/_+/,` $&_
                              `+s[r](e,'/$& \')[r](e=/_/g,' ')))[r](/ *\_+/,s=>s[r](e,' ')+` /
                              `+s[r](/_/,'__'))


                              Try it online!



                              Commented



                              NB: Alternate characters are used below for the regex delimiters to prevent SE syntax highlighter from going berserk.



                              s =>                       // s = input
                              s[r = 'replace']( // r = alias for 'replace'
                              // STEP #1
                              ∕S ∕g, // insert two middle spaces for all lines
                              '$& ' // that contain a border, followed by a space
                              ) // (i.e. all lines except the first and the last one)
                              [r]( // STEP #2
                              ∕.*∕, // isolate the first line
                              s => // let s be this first line
                              s[r]( //
                              e = ∕_+∕, // find the sequence of underscores and replace it with:
                              ` $&_n` + // the same sequence preceded by a space and followed by '_'
                              s[r]( // followed by a linefeed and:
                              e, // the same sequence preceded by '/' and followed by ' '
                              '/$& \' //
                              ) // with:
                              [r](e = ∕_∕g, ' ') // all underscores replaced with spaces
                              )) //
                              [r]( // STEP #3
                              ∕ *\_+∕, // isolate the last line, without the trailing '/'
                              s => // let s be this last line
                              s[r](e, ' ') + // replace all underscores with spaces
                              ` /n ` + // append 3 spaces and a trailing '/', followed by a linefeed
                              s[r](∕_∕, '__') // append s with an extra underscore
                              ) //





                              share|improve this answer











                              $endgroup$


















                                5












                                $begingroup$

                                JavaScript (ES6),  159 156 153  150 bytes





                                s=>s[r='replace'](/S /g,'$&   ')[r](/.*/,s=>s[r](e=/_+/,` $&_
                                `+s[r](e,'/$& \')[r](e=/_/g,' ')))[r](/ *\_+/,s=>s[r](e,' ')+` /
                                `+s[r](/_/,'__'))


                                Try it online!



                                Commented



                                NB: Alternate characters are used below for the regex delimiters to prevent SE syntax highlighter from going berserk.



                                s =>                       // s = input
                                s[r = 'replace']( // r = alias for 'replace'
                                // STEP #1
                                ∕S ∕g, // insert two middle spaces for all lines
                                '$& ' // that contain a border, followed by a space
                                ) // (i.e. all lines except the first and the last one)
                                [r]( // STEP #2
                                ∕.*∕, // isolate the first line
                                s => // let s be this first line
                                s[r]( //
                                e = ∕_+∕, // find the sequence of underscores and replace it with:
                                ` $&_n` + // the same sequence preceded by a space and followed by '_'
                                s[r]( // followed by a linefeed and:
                                e, // the same sequence preceded by '/' and followed by ' '
                                '/$& \' //
                                ) // with:
                                [r](e = ∕_∕g, ' ') // all underscores replaced with spaces
                                )) //
                                [r]( // STEP #3
                                ∕ *\_+∕, // isolate the last line, without the trailing '/'
                                s => // let s be this last line
                                s[r](e, ' ') + // replace all underscores with spaces
                                ` /n ` + // append 3 spaces and a trailing '/', followed by a linefeed
                                s[r](∕_∕, '__') // append s with an extra underscore
                                ) //





                                share|improve this answer











                                $endgroup$
















                                  5












                                  5








                                  5





                                  $begingroup$

                                  JavaScript (ES6),  159 156 153  150 bytes





                                  s=>s[r='replace'](/S /g,'$&   ')[r](/.*/,s=>s[r](e=/_+/,` $&_
                                  `+s[r](e,'/$& \')[r](e=/_/g,' ')))[r](/ *\_+/,s=>s[r](e,' ')+` /
                                  `+s[r](/_/,'__'))


                                  Try it online!



                                  Commented



                                  NB: Alternate characters are used below for the regex delimiters to prevent SE syntax highlighter from going berserk.



                                  s =>                       // s = input
                                  s[r = 'replace']( // r = alias for 'replace'
                                  // STEP #1
                                  ∕S ∕g, // insert two middle spaces for all lines
                                  '$& ' // that contain a border, followed by a space
                                  ) // (i.e. all lines except the first and the last one)
                                  [r]( // STEP #2
                                  ∕.*∕, // isolate the first line
                                  s => // let s be this first line
                                  s[r]( //
                                  e = ∕_+∕, // find the sequence of underscores and replace it with:
                                  ` $&_n` + // the same sequence preceded by a space and followed by '_'
                                  s[r]( // followed by a linefeed and:
                                  e, // the same sequence preceded by '/' and followed by ' '
                                  '/$& \' //
                                  ) // with:
                                  [r](e = ∕_∕g, ' ') // all underscores replaced with spaces
                                  )) //
                                  [r]( // STEP #3
                                  ∕ *\_+∕, // isolate the last line, without the trailing '/'
                                  s => // let s be this last line
                                  s[r](e, ' ') + // replace all underscores with spaces
                                  ` /n ` + // append 3 spaces and a trailing '/', followed by a linefeed
                                  s[r](∕_∕, '__') // append s with an extra underscore
                                  ) //





                                  share|improve this answer











                                  $endgroup$



                                  JavaScript (ES6),  159 156 153  150 bytes





                                  s=>s[r='replace'](/S /g,'$&   ')[r](/.*/,s=>s[r](e=/_+/,` $&_
                                  `+s[r](e,'/$& \')[r](e=/_/g,' ')))[r](/ *\_+/,s=>s[r](e,' ')+` /
                                  `+s[r](/_/,'__'))


                                  Try it online!



                                  Commented



                                  NB: Alternate characters are used below for the regex delimiters to prevent SE syntax highlighter from going berserk.



                                  s =>                       // s = input
                                  s[r = 'replace']( // r = alias for 'replace'
                                  // STEP #1
                                  ∕S ∕g, // insert two middle spaces for all lines
                                  '$& ' // that contain a border, followed by a space
                                  ) // (i.e. all lines except the first and the last one)
                                  [r]( // STEP #2
                                  ∕.*∕, // isolate the first line
                                  s => // let s be this first line
                                  s[r]( //
                                  e = ∕_+∕, // find the sequence of underscores and replace it with:
                                  ` $&_n` + // the same sequence preceded by a space and followed by '_'
                                  s[r]( // followed by a linefeed and:
                                  e, // the same sequence preceded by '/' and followed by ' '
                                  '/$& \' //
                                  ) // with:
                                  [r](e = ∕_∕g, ' ') // all underscores replaced with spaces
                                  )) //
                                  [r]( // STEP #3
                                  ∕ *\_+∕, // isolate the last line, without the trailing '/'
                                  s => // let s be this last line
                                  s[r](e, ' ') + // replace all underscores with spaces
                                  ` /n ` + // append 3 spaces and a trailing '/', followed by a linefeed
                                  s[r](∕_∕, '__') // append s with an extra underscore
                                  ) //






                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited May 18 at 23:58

























                                  answered May 18 at 10:40









                                  ArnauldArnauld

                                  88.2k7 gold badges103 silver badges360 bronze badges




                                  88.2k7 gold badges103 silver badges360 bronze badges























                                      2












                                      $begingroup$


                                      Charcoal, 48 bytes



                                      SθW¬№ω_≔⁺ωSω≔⊕⊘№ωη≔⊕⊘№ω/ζ≔×_⊕№ω_θ↗ζθ↓↘η←↙ζ↑←θ↖η


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



                                      SθW¬№ω_≔⁺ωSω


                                      Input and concatenate all of the lines except the first. (Input in JSON format would make most of this unnecessary at a saving of 11 bytes.)



                                      ≔⊕⊘№ωη≔⊕⊘№ω/ζ≔×_⊕№ω_θ


                                      Count the number of /s, /s, and _s in the string and use that to calculate the new side lengths (in the case of _s, as a string of _s of that length).



                                      ↗ζθ↓↘η←↙ζ↑←θ↖η


                                      Draw the enlarged hexagon.



                                      Alternative solution, also 48 bytes:



                                      SθW¬№ω_≔⁺ωSω≔⁺θωθF²«≔E/_⊕⊘№θκη×_⊟ηM⁰¬ιFη«↷¹κ↷¹¶


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



                                      SθW¬№ω_≔⁺ωSω≔⁺θωθ


                                      Input all of the lines. (Input in JSON format would make this unnecessary at a saving of 17 bytes.)



                                      F²«


                                      Draw the top right and bottom left sections of the hexagon separately.



                                      ≔E/_⊕⊘№θκ


                                      Count the number of /s, /s, and _s in the string and use that to calculate the new side lengths.



                                      η×_⊟ηM⁰¬ι


                                      Output the top or bottom, and move down a line if this was the top line.



                                      Fη«↷¹κ↷¹¶


                                      Draw both of the right or left sides.






                                      share|improve this answer









                                      $endgroup$


















                                        2












                                        $begingroup$


                                        Charcoal, 48 bytes



                                        SθW¬№ω_≔⁺ωSω≔⊕⊘№ωη≔⊕⊘№ω/ζ≔×_⊕№ω_θ↗ζθ↓↘η←↙ζ↑←θ↖η


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



                                        SθW¬№ω_≔⁺ωSω


                                        Input and concatenate all of the lines except the first. (Input in JSON format would make most of this unnecessary at a saving of 11 bytes.)



                                        ≔⊕⊘№ωη≔⊕⊘№ω/ζ≔×_⊕№ω_θ


                                        Count the number of /s, /s, and _s in the string and use that to calculate the new side lengths (in the case of _s, as a string of _s of that length).



                                        ↗ζθ↓↘η←↙ζ↑←θ↖η


                                        Draw the enlarged hexagon.



                                        Alternative solution, also 48 bytes:



                                        SθW¬№ω_≔⁺ωSω≔⁺θωθF²«≔E/_⊕⊘№θκη×_⊟ηM⁰¬ιFη«↷¹κ↷¹¶


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



                                        SθW¬№ω_≔⁺ωSω≔⁺θωθ


                                        Input all of the lines. (Input in JSON format would make this unnecessary at a saving of 17 bytes.)



                                        F²«


                                        Draw the top right and bottom left sections of the hexagon separately.



                                        ≔E/_⊕⊘№θκ


                                        Count the number of /s, /s, and _s in the string and use that to calculate the new side lengths.



                                        η×_⊟ηM⁰¬ι


                                        Output the top or bottom, and move down a line if this was the top line.



                                        Fη«↷¹κ↷¹¶


                                        Draw both of the right or left sides.






                                        share|improve this answer









                                        $endgroup$
















                                          2












                                          2








                                          2





                                          $begingroup$


                                          Charcoal, 48 bytes



                                          SθW¬№ω_≔⁺ωSω≔⊕⊘№ωη≔⊕⊘№ω/ζ≔×_⊕№ω_θ↗ζθ↓↘η←↙ζ↑←θ↖η


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



                                          SθW¬№ω_≔⁺ωSω


                                          Input and concatenate all of the lines except the first. (Input in JSON format would make most of this unnecessary at a saving of 11 bytes.)



                                          ≔⊕⊘№ωη≔⊕⊘№ω/ζ≔×_⊕№ω_θ


                                          Count the number of /s, /s, and _s in the string and use that to calculate the new side lengths (in the case of _s, as a string of _s of that length).



                                          ↗ζθ↓↘η←↙ζ↑←θ↖η


                                          Draw the enlarged hexagon.



                                          Alternative solution, also 48 bytes:



                                          SθW¬№ω_≔⁺ωSω≔⁺θωθF²«≔E/_⊕⊘№θκη×_⊟ηM⁰¬ιFη«↷¹κ↷¹¶


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



                                          SθW¬№ω_≔⁺ωSω≔⁺θωθ


                                          Input all of the lines. (Input in JSON format would make this unnecessary at a saving of 17 bytes.)



                                          F²«


                                          Draw the top right and bottom left sections of the hexagon separately.



                                          ≔E/_⊕⊘№θκ


                                          Count the number of /s, /s, and _s in the string and use that to calculate the new side lengths.



                                          η×_⊟ηM⁰¬ι


                                          Output the top or bottom, and move down a line if this was the top line.



                                          Fη«↷¹κ↷¹¶


                                          Draw both of the right or left sides.






                                          share|improve this answer









                                          $endgroup$




                                          Charcoal, 48 bytes



                                          SθW¬№ω_≔⁺ωSω≔⊕⊘№ωη≔⊕⊘№ω/ζ≔×_⊕№ω_θ↗ζθ↓↘η←↙ζ↑←θ↖η


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



                                          SθW¬№ω_≔⁺ωSω


                                          Input and concatenate all of the lines except the first. (Input in JSON format would make most of this unnecessary at a saving of 11 bytes.)



                                          ≔⊕⊘№ωη≔⊕⊘№ω/ζ≔×_⊕№ω_θ


                                          Count the number of /s, /s, and _s in the string and use that to calculate the new side lengths (in the case of _s, as a string of _s of that length).



                                          ↗ζθ↓↘η←↙ζ↑←θ↖η


                                          Draw the enlarged hexagon.



                                          Alternative solution, also 48 bytes:



                                          SθW¬№ω_≔⁺ωSω≔⁺θωθF²«≔E/_⊕⊘№θκη×_⊟ηM⁰¬ιFη«↷¹κ↷¹¶


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



                                          SθW¬№ω_≔⁺ωSω≔⁺θωθ


                                          Input all of the lines. (Input in JSON format would make this unnecessary at a saving of 17 bytes.)



                                          F²«


                                          Draw the top right and bottom left sections of the hexagon separately.



                                          ≔E/_⊕⊘№θκ


                                          Count the number of /s, /s, and _s in the string and use that to calculate the new side lengths.



                                          η×_⊟ηM⁰¬ι


                                          Output the top or bottom, and move down a line if this was the top line.



                                          Fη«↷¹κ↷¹¶


                                          Draw both of the right or left sides.







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered May 18 at 13:22









                                          NeilNeil

                                          86.2k8 gold badges46 silver badges183 bronze badges




                                          86.2k8 gold badges46 silver badges183 bronze badges























                                              2












                                              $begingroup$


                                              APL (Dyalog Unicode), 75 74 bytesSBCS





                                              ' /_'∘{⍺[a×1=(+⍀×a)⌊⊖+⍀⊖×a←2⌈/{⊃0~⍨1⌷⍵,⍨⍉⍵}⌺3 3(0,0,⍨⍉)⍣3⍉⍺⍳↑⍵]}'.+'⎕s'&'


                                              Try it online!



                                              '.+'⎕s'&' split input into lines



                                              ↑⍵ mix lines into a matrix



                                              ⍺⍳ replace ' /_' with 0 1 2 3



                                              (0,0,⍨⍉)⍣3⍉ surround with a layer of 0s on top&bottom and two layers of 0s on the left&right



                                              {⊃0~⍨1⌷⍵,⍨⍉⍵}⌺3 3 for each cell choose the first non-0 from: upper, lower, left, right from the 3x3 neighbourhood centred on it



                                              2⌈/ max in pairs horizontally



                                              a×1=(+⍀×a)⌊⊖+⍀⊖×a← keep only the outer boundary of non-0s



                                              ⍺[ ] replace 0 1 2 3 with ' /_'






                                              share|improve this answer











                                              $endgroup$


















                                                2












                                                $begingroup$


                                                APL (Dyalog Unicode), 75 74 bytesSBCS





                                                ' /_'∘{⍺[a×1=(+⍀×a)⌊⊖+⍀⊖×a←2⌈/{⊃0~⍨1⌷⍵,⍨⍉⍵}⌺3 3(0,0,⍨⍉)⍣3⍉⍺⍳↑⍵]}'.+'⎕s'&'


                                                Try it online!



                                                '.+'⎕s'&' split input into lines



                                                ↑⍵ mix lines into a matrix



                                                ⍺⍳ replace ' /_' with 0 1 2 3



                                                (0,0,⍨⍉)⍣3⍉ surround with a layer of 0s on top&bottom and two layers of 0s on the left&right



                                                {⊃0~⍨1⌷⍵,⍨⍉⍵}⌺3 3 for each cell choose the first non-0 from: upper, lower, left, right from the 3x3 neighbourhood centred on it



                                                2⌈/ max in pairs horizontally



                                                a×1=(+⍀×a)⌊⊖+⍀⊖×a← keep only the outer boundary of non-0s



                                                ⍺[ ] replace 0 1 2 3 with ' /_'






                                                share|improve this answer











                                                $endgroup$
















                                                  2












                                                  2








                                                  2





                                                  $begingroup$


                                                  APL (Dyalog Unicode), 75 74 bytesSBCS





                                                  ' /_'∘{⍺[a×1=(+⍀×a)⌊⊖+⍀⊖×a←2⌈/{⊃0~⍨1⌷⍵,⍨⍉⍵}⌺3 3(0,0,⍨⍉)⍣3⍉⍺⍳↑⍵]}'.+'⎕s'&'


                                                  Try it online!



                                                  '.+'⎕s'&' split input into lines



                                                  ↑⍵ mix lines into a matrix



                                                  ⍺⍳ replace ' /_' with 0 1 2 3



                                                  (0,0,⍨⍉)⍣3⍉ surround with a layer of 0s on top&bottom and two layers of 0s on the left&right



                                                  {⊃0~⍨1⌷⍵,⍨⍉⍵}⌺3 3 for each cell choose the first non-0 from: upper, lower, left, right from the 3x3 neighbourhood centred on it



                                                  2⌈/ max in pairs horizontally



                                                  a×1=(+⍀×a)⌊⊖+⍀⊖×a← keep only the outer boundary of non-0s



                                                  ⍺[ ] replace 0 1 2 3 with ' /_'






                                                  share|improve this answer











                                                  $endgroup$




                                                  APL (Dyalog Unicode), 75 74 bytesSBCS





                                                  ' /_'∘{⍺[a×1=(+⍀×a)⌊⊖+⍀⊖×a←2⌈/{⊃0~⍨1⌷⍵,⍨⍉⍵}⌺3 3(0,0,⍨⍉)⍣3⍉⍺⍳↑⍵]}'.+'⎕s'&'


                                                  Try it online!



                                                  '.+'⎕s'&' split input into lines



                                                  ↑⍵ mix lines into a matrix



                                                  ⍺⍳ replace ' /_' with 0 1 2 3



                                                  (0,0,⍨⍉)⍣3⍉ surround with a layer of 0s on top&bottom and two layers of 0s on the left&right



                                                  {⊃0~⍨1⌷⍵,⍨⍉⍵}⌺3 3 for each cell choose the first non-0 from: upper, lower, left, right from the 3x3 neighbourhood centred on it



                                                  2⌈/ max in pairs horizontally



                                                  a×1=(+⍀×a)⌊⊖+⍀⊖×a← keep only the outer boundary of non-0s



                                                  ⍺[ ] replace 0 1 2 3 with ' /_'







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited May 19 at 16:19

























                                                  answered May 19 at 15:43









                                                  ngnngn

                                                  7,7161 gold badge27 silver badges61 bronze badges




                                                  7,7161 gold badge27 silver badges61 bronze badges























                                                      0












                                                      $begingroup$


                                                      Perl 5, 177 156 145 bytes





                                                      @l=pop=~/.+/g;splice@l,$_,0,$l[$_]=~s,_, ,gr for-1,1;$l[$_]=~s, (S)( +)(S),$_<2?" $1$2 $3":"$1$2   $3",e for 1..@l-2;join("n",@l)=~s,_+,$&_,gr


                                                      Could be shorter? Don't see how just yet. With comments and added newlines and header+footer:



                                                      sub f {
                                                      @l=pop=~/.+/g; #1
                                                      splice@l,$_,0,$l[$_]=~s,_, ,gr for-1,1; #2
                                                      $l[$_]=~s, (S)( +)(S),$_<2?" $1$2 $3":"$1$2 $3",e for 1..@l-2; #3
                                                      join("n",@l)=~s,_+,$&_,gr #4
                                                      }


                                                      Try it online!



                                                      Line #1 splits multi-line input string into the @l array.



                                                      Line #2 duplicates second and last lines without the _ chars.



                                                      Line #3 adds spaces where needed on line 2 to second last.



                                                      Line #4 widens the two ___ sides with one _ and returns the @l array of lines as one multi-line string.






                                                      share|improve this answer











                                                      $endgroup$


















                                                        0












                                                        $begingroup$


                                                        Perl 5, 177 156 145 bytes





                                                        @l=pop=~/.+/g;splice@l,$_,0,$l[$_]=~s,_, ,gr for-1,1;$l[$_]=~s, (S)( +)(S),$_<2?" $1$2 $3":"$1$2   $3",e for 1..@l-2;join("n",@l)=~s,_+,$&_,gr


                                                        Could be shorter? Don't see how just yet. With comments and added newlines and header+footer:



                                                        sub f {
                                                        @l=pop=~/.+/g; #1
                                                        splice@l,$_,0,$l[$_]=~s,_, ,gr for-1,1; #2
                                                        $l[$_]=~s, (S)( +)(S),$_<2?" $1$2 $3":"$1$2 $3",e for 1..@l-2; #3
                                                        join("n",@l)=~s,_+,$&_,gr #4
                                                        }


                                                        Try it online!



                                                        Line #1 splits multi-line input string into the @l array.



                                                        Line #2 duplicates second and last lines without the _ chars.



                                                        Line #3 adds spaces where needed on line 2 to second last.



                                                        Line #4 widens the two ___ sides with one _ and returns the @l array of lines as one multi-line string.






                                                        share|improve this answer











                                                        $endgroup$
















                                                          0












                                                          0








                                                          0





                                                          $begingroup$


                                                          Perl 5, 177 156 145 bytes





                                                          @l=pop=~/.+/g;splice@l,$_,0,$l[$_]=~s,_, ,gr for-1,1;$l[$_]=~s, (S)( +)(S),$_<2?" $1$2 $3":"$1$2   $3",e for 1..@l-2;join("n",@l)=~s,_+,$&_,gr


                                                          Could be shorter? Don't see how just yet. With comments and added newlines and header+footer:



                                                          sub f {
                                                          @l=pop=~/.+/g; #1
                                                          splice@l,$_,0,$l[$_]=~s,_, ,gr for-1,1; #2
                                                          $l[$_]=~s, (S)( +)(S),$_<2?" $1$2 $3":"$1$2 $3",e for 1..@l-2; #3
                                                          join("n",@l)=~s,_+,$&_,gr #4
                                                          }


                                                          Try it online!



                                                          Line #1 splits multi-line input string into the @l array.



                                                          Line #2 duplicates second and last lines without the _ chars.



                                                          Line #3 adds spaces where needed on line 2 to second last.



                                                          Line #4 widens the two ___ sides with one _ and returns the @l array of lines as one multi-line string.






                                                          share|improve this answer











                                                          $endgroup$




                                                          Perl 5, 177 156 145 bytes





                                                          @l=pop=~/.+/g;splice@l,$_,0,$l[$_]=~s,_, ,gr for-1,1;$l[$_]=~s, (S)( +)(S),$_<2?" $1$2 $3":"$1$2   $3",e for 1..@l-2;join("n",@l)=~s,_+,$&_,gr


                                                          Could be shorter? Don't see how just yet. With comments and added newlines and header+footer:



                                                          sub f {
                                                          @l=pop=~/.+/g; #1
                                                          splice@l,$_,0,$l[$_]=~s,_, ,gr for-1,1; #2
                                                          $l[$_]=~s, (S)( +)(S),$_<2?" $1$2 $3":"$1$2 $3",e for 1..@l-2; #3
                                                          join("n",@l)=~s,_+,$&_,gr #4
                                                          }


                                                          Try it online!



                                                          Line #1 splits multi-line input string into the @l array.



                                                          Line #2 duplicates second and last lines without the _ chars.



                                                          Line #3 adds spaces where needed on line 2 to second last.



                                                          Line #4 widens the two ___ sides with one _ and returns the @l array of lines as one multi-line string.







                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited May 19 at 14:19

























                                                          answered May 19 at 13:16









                                                          Kjetil S.Kjetil S.

                                                          6692 silver badges5 bronze badges




                                                          6692 silver badges5 bronze badges






























                                                              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%2f185760%2fexpand-a-hexagon%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

                                                              Færeyskur hestur Heimild | Tengill | Tilvísanir | LeiðsagnarvalRossið - síða um færeyska hrossið á færeyskuGott ár hjá færeyska hestinum

                                                              He _____ here since 1970 . Answer needed [closed]What does “since he was so high” mean?Meaning of “catch birds for”?How do I ensure “since” takes the meaning I want?“Who cares here” meaningWhat does “right round toward” mean?the time tense (had now been detected)What does the phrase “ring around the roses” mean here?Correct usage of “visited upon”Meaning of “foiled rail sabotage bid”It was the third time I had gone to Rome or It is the third time I had been to Rome

                                                              Slayer Innehåll Historia | Stil, komposition och lyrik | Bandets betydelse och framgångar | Sidoprojekt och samarbeten | Kontroverser | Medlemmar | Utmärkelser och nomineringar | Turnéer och festivaler | Diskografi | Referenser | Externa länkar | Navigeringsmenywww.slayer.net”Metal Massacre vol. 1””Metal Massacre vol. 3””Metal Massacre Volume III””Show No Mercy””Haunting the Chapel””Live Undead””Hell Awaits””Reign in Blood””Reign in Blood””Gold & Platinum – Reign in Blood””Golden Gods Awards Winners”originalet”Kerrang! Hall Of Fame””Slayer Looks Back On 37-Year Career In New Video Series: Part Two””South of Heaven””Gold & Platinum – South of Heaven””Seasons in the Abyss””Gold & Platinum - Seasons in the Abyss””Divine Intervention””Divine Intervention - Release group by Slayer””Gold & Platinum - Divine Intervention””Live Intrusion””Undisputed Attitude””Abolish Government/Superficial Love””Release “Slatanic Slaughter: A Tribute to Slayer” by Various Artists””Diabolus in Musica””Soundtrack to the Apocalypse””God Hates Us All””Systematic - Relationships””War at the Warfield””Gold & Platinum - War at the Warfield””Soundtrack to the Apocalypse””Gold & Platinum - Still Reigning””Metallica, Slayer, Iron Mauden Among Winners At Metal Hammer Awards””Eternal Pyre””Eternal Pyre - Slayer release group””Eternal Pyre””Metal Storm Awards 2006””Kerrang! Hall Of Fame””Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Bullet-For My Valentine booed at Metal Hammer Golden Gods Awards””Unholy Aliance””The End Of Slayer?””Slayer: We Could Thrash Out Two More Albums If We're Fast Enough...””'The Unholy Alliance: Chapter III' UK Dates Added”originalet”Megadeth And Slayer To Co-Headline 'Canadian Carnage' Trek”originalet”World Painted Blood””Release “World Painted Blood” by Slayer””Metallica Heading To Cinemas””Slayer, Megadeth To Join Forces For 'European Carnage' Tour - Dec. 18, 2010”originalet”Slayer's Hanneman Contracts Acute Infection; Band To Bring In Guest Guitarist””Cannibal Corpse's Pat O'Brien Will Step In As Slayer's Guest Guitarist”originalet”Slayer’s Jeff Hanneman Dead at 49””Dave Lombardo Says He Made Only $67,000 In 2011 While Touring With Slayer””Slayer: We Do Not Agree With Dave Lombardo's Substance Or Timeline Of Events””Slayer Welcomes Drummer Paul Bostaph Back To The Fold””Slayer Hope to Unveil Never-Before-Heard Jeff Hanneman Material on Next Album””Slayer Debut New Song 'Implode' During Surprise Golden Gods Appearance””Release group Repentless by Slayer””Repentless - Slayer - Credits””Slayer””Metal Storm Awards 2015””Slayer - to release comic book "Repentless #1"””Slayer To Release 'Repentless' 6.66" Vinyl Box Set””BREAKING NEWS: Slayer Announce Farewell Tour””Slayer Recruit Lamb of God, Anthrax, Behemoth + Testament for Final Tour””Slayer lägger ner efter 37 år””Slayer Announces Second North American Leg Of 'Final' Tour””Final World Tour””Slayer Announces Final European Tour With Lamb of God, Anthrax And Obituary””Slayer To Tour Europe With Lamb of God, Anthrax And Obituary””Slayer To Play 'Last French Show Ever' At Next Year's Hellfst””Slayer's Final World Tour Will Extend Into 2019””Death Angel's Rob Cavestany On Slayer's 'Farewell' Tour: 'Some Of Us Could See This Coming'””Testament Has No Plans To Retire Anytime Soon, Says Chuck Billy””Anthrax's Scott Ian On Slayer's 'Farewell' Tour Plans: 'I Was Surprised And I Wasn't Surprised'””Slayer””Slayer's Morbid Schlock””Review/Rock; For Slayer, the Mania Is the Message””Slayer - Biography””Slayer - Reign In Blood”originalet”Dave Lombardo””An exclusive oral history of Slayer”originalet”Exclusive! Interview With Slayer Guitarist Jeff Hanneman”originalet”Thinking Out Loud: Slayer's Kerry King on hair metal, Satan and being polite””Slayer Lyrics””Slayer - Biography””Most influential artists for extreme metal music””Slayer - Reign in Blood””Slayer guitarist Jeff Hanneman dies aged 49””Slatanic Slaughter: A Tribute to Slayer””Gateway to Hell: A Tribute to Slayer””Covered In Blood””Slayer: The Origins of Thrash in San Francisco, CA.””Why They Rule - #6 Slayer”originalet”Guitar World's 100 Greatest Heavy Metal Guitarists Of All Time”originalet”The fans have spoken: Slayer comes out on top in readers' polls”originalet”Tribute to Jeff Hanneman (1964-2013)””Lamb Of God Frontman: We Sound Like A Slayer Rip-Off””BEHEMOTH Frontman Pays Tribute To SLAYER's JEFF HANNEMAN””Slayer, Hatebreed Doing Double Duty On This Year's Ozzfest””System of a Down””Lacuna Coil’s Andrea Ferro Talks Influences, Skateboarding, Band Origins + More””Slayer - Reign in Blood””Into The Lungs of Hell””Slayer rules - en utställning om fans””Slayer and Their Fans Slashed Through a No-Holds-Barred Night at Gas Monkey””Home””Slayer””Gold & Platinum - The Big 4 Live from Sofia, Bulgaria””Exclusive! Interview With Slayer Guitarist Kerry King””2008-02-23: Wiltern, Los Angeles, CA, USA””Slayer's Kerry King To Perform With Megadeth Tonight! - Oct. 21, 2010”originalet”Dave Lombardo - Biography”Slayer Case DismissedArkiveradUltimate Classic Rock: Slayer guitarist Jeff Hanneman dead at 49.”Slayer: "We could never do any thing like Some Kind Of Monster..."””Cannibal Corpse'S Pat O'Brien Will Step In As Slayer'S Guest Guitarist | The Official Slayer Site”originalet”Slayer Wins 'Best Metal' Grammy Award””Slayer Guitarist Jeff Hanneman Dies””Kerrang! Awards 2006 Blog: Kerrang! Hall Of Fame””Kerrang! Awards 2013: Kerrang! Legend”originalet”Metallica, Slayer, Iron Maien Among Winners At Metal Hammer Awards””Metal Hammer Golden Gods Awards””Bullet For My Valentine Booed At Metal Hammer Golden Gods Awards””Metal Storm Awards 2006””Metal Storm Awards 2015””Slayer's Concert History””Slayer - Relationships””Slayer - Releases”Slayers officiella webbplatsSlayer på MusicBrainzOfficiell webbplatsSlayerSlayerr1373445760000 0001 1540 47353068615-5086262726cb13906545x(data)6033143kn20030215029