ASCII Art Octagons

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite












Given an input integer n > 1, output an ASCII-art octagon with side lengths composed of n characters. See examples below:



n=2
##
# #
# #
##

n=3
###
# #
# #
# #
# #
# #
###

n=4
####
# #
# #
# #
# #
# #
# #
# #
# #
####

n=5
#####
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#####

and so on.


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



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



Rules and I/O



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

  • You can use any printable ASCII character instead of the # (except space), but the "background" character must be space (ASCII 32).

  • Either a full program or a function are acceptable.


  • 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























  • Can we use different output characters, or does it need to be consistent?
    – Emigna
    22 mins ago










  • @Emigna Different characters are fine.
    – AdmBorkBork
    9 mins ago














up vote
5
down vote

favorite












Given an input integer n > 1, output an ASCII-art octagon with side lengths composed of n characters. See examples below:



n=2
##
# #
# #
##

n=3
###
# #
# #
# #
# #
# #
###

n=4
####
# #
# #
# #
# #
# #
# #
# #
# #
####

n=5
#####
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#####

and so on.


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



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



Rules and I/O



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

  • You can use any printable ASCII character instead of the # (except space), but the "background" character must be space (ASCII 32).

  • Either a full program or a function are acceptable.


  • 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























  • Can we use different output characters, or does it need to be consistent?
    – Emigna
    22 mins ago










  • @Emigna Different characters are fine.
    – AdmBorkBork
    9 mins ago












up vote
5
down vote

favorite









up vote
5
down vote

favorite











Given an input integer n > 1, output an ASCII-art octagon with side lengths composed of n characters. See examples below:



n=2
##
# #
# #
##

n=3
###
# #
# #
# #
# #
# #
###

n=4
####
# #
# #
# #
# #
# #
# #
# #
# #
####

n=5
#####
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#####

and so on.


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



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



Rules and I/O



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

  • You can use any printable ASCII character instead of the # (except space), but the "background" character must be space (ASCII 32).

  • Either a full program or a function are acceptable.


  • 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















Given an input integer n > 1, output an ASCII-art octagon with side lengths composed of n characters. See examples below:



n=2
##
# #
# #
##

n=3
###
# #
# #
# #
# #
# #
###

n=4
####
# #
# #
# #
# #
# #
# #
# #
# #
####

n=5
#####
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#####

and so on.


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



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



Rules and I/O



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

  • You can use any printable ASCII character instead of the # (except space), but the "background" character must be space (ASCII 32).

  • Either a full program or a function are acceptable.


  • 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 40 mins ago

























asked 45 mins ago









AdmBorkBork

25.2k361220




25.2k361220











  • Can we use different output characters, or does it need to be consistent?
    – Emigna
    22 mins ago










  • @Emigna Different characters are fine.
    – AdmBorkBork
    9 mins ago
















  • Can we use different output characters, or does it need to be consistent?
    – Emigna
    22 mins ago










  • @Emigna Different characters are fine.
    – AdmBorkBork
    9 mins ago















Can we use different output characters, or does it need to be consistent?
– Emigna
22 mins ago




Can we use different output characters, or does it need to be consistent?
– Emigna
22 mins ago












@Emigna Different characters are fine.
– AdmBorkBork
9 mins ago




@Emigna Different characters are fine.
– AdmBorkBork
9 mins ago










4 Answers
4






active

oldest

votes

















up vote
4
down vote














05AB1E, 3 bytes



7ÝΛ


Try it online!



Explanation



 # implicit input as length
# implicit input as string to print
7Ý # range [0...7] as directions
Λ # canvas print


See this answer to understand the 05AB1E canvas.






share|improve this answer





























    up vote
    2
    down vote














    Canvas, 15 14 12 bytes



    /⁸⇵╷+×+:⤢n╬┼


    Try it here!



    Explanation:



    / a diagonal of length n
    ⁸ the input,
    ⇵ ceiling divided by 2, (storing the remainder)
    ╷ minus one
    #× repeat "#" that many times
    + append that to the diagonal
    :⤢n overlap that with its transpose
    ╬┼ quad-palindromize with the overlap being the remainder stored earlier





    share|improve this answer





























      up vote
      0
      down vote














      Charcoal, 5 bytes



      GH*N#


      My first answer with Charcoal!



      Explaination:



      GH*N# //Full program
      GH //Draw a hollow polygon
      * //with 8 sides
      ï¼® //of side length from input
      # //using '#' character


      Try it online!






      share|improve this answer





























        up vote
        0
        down vote














        R, 122 bytes





        function(n)m=matrix(" ",y<-3*n-2,y)
        m[cbind(c(x<-c(rep(1,n-1),1:(2*n-1)),y+1-x),rev(x))]=0
        write(pmax(m,rev(m)),1,y,,"")


        Try it online!





        share




















          Your Answer





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

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

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

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

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: 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%2f175408%2fascii-art-octagons%23new-answer', 'question_page');

          );

          Post as a guest






























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          4
          down vote














          05AB1E, 3 bytes



          7ÝΛ


          Try it online!



          Explanation



           # implicit input as length
          # implicit input as string to print
          7Ý # range [0...7] as directions
          Λ # canvas print


          See this answer to understand the 05AB1E canvas.






          share|improve this answer


























            up vote
            4
            down vote














            05AB1E, 3 bytes



            7ÝΛ


            Try it online!



            Explanation



             # implicit input as length
            # implicit input as string to print
            7Ý # range [0...7] as directions
            Λ # canvas print


            See this answer to understand the 05AB1E canvas.






            share|improve this answer
























              up vote
              4
              down vote










              up vote
              4
              down vote










              05AB1E, 3 bytes



              7ÝΛ


              Try it online!



              Explanation



               # implicit input as length
              # implicit input as string to print
              7Ý # range [0...7] as directions
              Λ # canvas print


              See this answer to understand the 05AB1E canvas.






              share|improve this answer















              05AB1E, 3 bytes



              7ÝΛ


              Try it online!



              Explanation



               # implicit input as length
              # implicit input as string to print
              7Ý # range [0...7] as directions
              Λ # canvas print


              See this answer to understand the 05AB1E canvas.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 7 mins ago

























              answered 23 mins ago









              Emigna

              44.3k431134




              44.3k431134




















                  up vote
                  2
                  down vote














                  Canvas, 15 14 12 bytes



                  /⁸⇵╷+×+:⤢n╬┼


                  Try it here!



                  Explanation:



                  / a diagonal of length n
                  ⁸ the input,
                  ⇵ ceiling divided by 2, (storing the remainder)
                  ╷ minus one
                  #× repeat "#" that many times
                  + append that to the diagonal
                  :⤢n overlap that with its transpose
                  ╬┼ quad-palindromize with the overlap being the remainder stored earlier





                  share|improve this answer


























                    up vote
                    2
                    down vote














                    Canvas, 15 14 12 bytes



                    /⁸⇵╷+×+:⤢n╬┼


                    Try it here!



                    Explanation:



                    / a diagonal of length n
                    ⁸ the input,
                    ⇵ ceiling divided by 2, (storing the remainder)
                    ╷ minus one
                    #× repeat "#" that many times
                    + append that to the diagonal
                    :⤢n overlap that with its transpose
                    ╬┼ quad-palindromize with the overlap being the remainder stored earlier





                    share|improve this answer
























                      up vote
                      2
                      down vote










                      up vote
                      2
                      down vote










                      Canvas, 15 14 12 bytes



                      /⁸⇵╷+×+:⤢n╬┼


                      Try it here!



                      Explanation:



                      / a diagonal of length n
                      ⁸ the input,
                      ⇵ ceiling divided by 2, (storing the remainder)
                      ╷ minus one
                      #× repeat "#" that many times
                      + append that to the diagonal
                      :⤢n overlap that with its transpose
                      ╬┼ quad-palindromize with the overlap being the remainder stored earlier





                      share|improve this answer















                      Canvas, 15 14 12 bytes



                      /⁸⇵╷+×+:⤢n╬┼


                      Try it here!



                      Explanation:



                      / a diagonal of length n
                      ⁸ the input,
                      ⇵ ceiling divided by 2, (storing the remainder)
                      ╷ minus one
                      #× repeat "#" that many times
                      + append that to the diagonal
                      :⤢n overlap that with its transpose
                      ╬┼ quad-palindromize with the overlap being the remainder stored earlier






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 10 mins ago

























                      answered 39 mins ago









                      dzaima

                      13.7k21653




                      13.7k21653




















                          up vote
                          0
                          down vote














                          Charcoal, 5 bytes



                          GH*N#


                          My first answer with Charcoal!



                          Explaination:



                          GH*N# //Full program
                          GH //Draw a hollow polygon
                          * //with 8 sides
                          ï¼® //of side length from input
                          # //using '#' character


                          Try it online!






                          share|improve this answer


























                            up vote
                            0
                            down vote














                            Charcoal, 5 bytes



                            GH*N#


                            My first answer with Charcoal!



                            Explaination:



                            GH*N# //Full program
                            GH //Draw a hollow polygon
                            * //with 8 sides
                            ï¼® //of side length from input
                            # //using '#' character


                            Try it online!






                            share|improve this answer
























                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote










                              Charcoal, 5 bytes



                              GH*N#


                              My first answer with Charcoal!



                              Explaination:



                              GH*N# //Full program
                              GH //Draw a hollow polygon
                              * //with 8 sides
                              ï¼® //of side length from input
                              # //using '#' character


                              Try it online!






                              share|improve this answer















                              Charcoal, 5 bytes



                              GH*N#


                              My first answer with Charcoal!



                              Explaination:



                              GH*N# //Full program
                              GH //Draw a hollow polygon
                              * //with 8 sides
                              ï¼® //of side length from input
                              # //using '#' character


                              Try it online!







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 5 mins ago

























                              answered 10 mins ago









                              Cowabunghole

                              863418




                              863418




















                                  up vote
                                  0
                                  down vote














                                  R, 122 bytes





                                  function(n)m=matrix(" ",y<-3*n-2,y)
                                  m[cbind(c(x<-c(rep(1,n-1),1:(2*n-1)),y+1-x),rev(x))]=0
                                  write(pmax(m,rev(m)),1,y,,"")


                                  Try it online!





                                  share
























                                    up vote
                                    0
                                    down vote














                                    R, 122 bytes





                                    function(n)m=matrix(" ",y<-3*n-2,y)
                                    m[cbind(c(x<-c(rep(1,n-1),1:(2*n-1)),y+1-x),rev(x))]=0
                                    write(pmax(m,rev(m)),1,y,,"")


                                    Try it online!





                                    share






















                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote










                                      R, 122 bytes





                                      function(n)m=matrix(" ",y<-3*n-2,y)
                                      m[cbind(c(x<-c(rep(1,n-1),1:(2*n-1)),y+1-x),rev(x))]=0
                                      write(pmax(m,rev(m)),1,y,,"")


                                      Try it online!





                                      share













                                      R, 122 bytes





                                      function(n)m=matrix(" ",y<-3*n-2,y)
                                      m[cbind(c(x<-c(rep(1,n-1),1:(2*n-1)),y+1-x),rev(x))]=0
                                      write(pmax(m,rev(m)),1,y,,"")


                                      Try it online!






                                      share











                                      share


                                      share










                                      answered 2 mins ago









                                      Giuseppe

                                      15.7k31051




                                      15.7k31051



























                                           

                                          draft saved


                                          draft discarded















































                                           


                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175408%2fascii-art-octagons%23new-answer', 'question_page');

                                          );

                                          Post as a guest













































































                                          Comments

                                          Popular posts from this blog

                                          Long meetings (6-7 hours a day): Being “babysat” by supervisor

                                          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                                          Confectionery