ASCII Art Octagons











up vote
20
down vote

favorite
3












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




















  • 1




    Can we use different output characters, or does it need to be consistent?
    – Emigna
    Nov 6 at 18:13










  • @Emigna Different characters are fine.
    – AdmBorkBork
    Nov 6 at 18:26






  • 1




    Quite related.
    – Charlie
    Nov 7 at 11:06















up vote
20
down vote

favorite
3












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




















  • 1




    Can we use different output characters, or does it need to be consistent?
    – Emigna
    Nov 6 at 18:13










  • @Emigna Different characters are fine.
    – AdmBorkBork
    Nov 6 at 18:26






  • 1




    Quite related.
    – Charlie
    Nov 7 at 11:06













up vote
20
down vote

favorite
3









up vote
20
down vote

favorite
3






3





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 Nov 6 at 17:55

























asked Nov 6 at 17:50









AdmBorkBork

25.5k362223




25.5k362223








  • 1




    Can we use different output characters, or does it need to be consistent?
    – Emigna
    Nov 6 at 18:13










  • @Emigna Different characters are fine.
    – AdmBorkBork
    Nov 6 at 18:26






  • 1




    Quite related.
    – Charlie
    Nov 7 at 11:06














  • 1




    Can we use different output characters, or does it need to be consistent?
    – Emigna
    Nov 6 at 18:13










  • @Emigna Different characters are fine.
    – AdmBorkBork
    Nov 6 at 18:26






  • 1




    Quite related.
    – Charlie
    Nov 7 at 11:06








1




1




Can we use different output characters, or does it need to be consistent?
– Emigna
Nov 6 at 18:13




Can we use different output characters, or does it need to be consistent?
– Emigna
Nov 6 at 18:13












@Emigna Different characters are fine.
– AdmBorkBork
Nov 6 at 18:26




@Emigna Different characters are fine.
– AdmBorkBork
Nov 6 at 18:26




1




1




Quite related.
– Charlie
Nov 7 at 11:06




Quite related.
– Charlie
Nov 7 at 11:06










18 Answers
18






active

oldest

votes

















up vote
20
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























  • Surely this should be 5 bytes? Or do code golf challenges see bytes and characters as interchangeable
    – Doug
    Nov 7 at 17:10






  • 3




    @Doug: It is 3 bytes in 05ab1e's code page
    – Emigna
    Nov 7 at 17:11










  • Oh, cool! Thanks for the docs link!
    – Doug
    Nov 7 at 17:58










  • >:( damnit, adnan
    – ASCII-only
    18 hours ago


















up vote
10
down vote













JavaScript (ES6), 114 106 105 104 103 bytes





n=>(g=x=>v=x*2>w?w-x:x,F=x=>~y?`# 
`[~x?(h=g(x--))*g(y)>0&h+v!=n|n>h+v:(y--,x=w,2)]+F(x):'')(y=w=--n*3)


Try it online!



How?



This builds the output character by character.



Given the input $n$, we compute:



$$n'=n-1\w=3n'$$



For each character at $(x,y)$, we compute $(h,v)$:



$$h=w/2-left|x-w/2right|\v=w/2-left|y-w/2right|$$



The cells belonging to the octagon satisfy one of the following conditions:




  • ($h=0$ OR $v=0$) AND $h+vge n'$ (in red below)


  • $h+v=n'$ (in orange below)


For example, with $n=4$ (and $n'=3$):



$$begin{matrix}(0,0)&(1,0)&(2,0)&color{red}{(3,0)}&color{red}{(4,0)}&color{red}{(4,0)}&color{red}{(3,0)}&(2,0)&(1,0)&(0,0)\
(0,1)&(1,1)&color{orange}{(2,1)}&(3,1)&(4,1)&(4,1)&(3,1)&color{orange}{(2,1)}&(1,1)&(0,1)\
(0,2)&color{orange}{(1,2)}&(2,2)&(3,2)&(4,2)&(4,2)&(3,2)&(2,2)&color{orange}{(1,2)}&(0,2)\
color{red}{(0,3)}&(1,3)&(2,3)&(3,3)&(4,3)&(4,3)&(3,3)&(2,3)&(1,3)&color{red}{(0,3)}\
color{red}{(0,4)}&(1,4)&(2,4)&(3,4)&(4,4)&(4,4)&(3,4)&(2,4)&(1,4)&color{red}{(0,4)}\
color{red}{(0,4)}&(1,4)&(2,4)&(3,4)&(4,4)&(4,4)&(3,4)&(2,4)&(1,4)&color{red}{(0,4)}\
color{red}{(0,3)}&(1,3)&(2,3)&(3,3)&(4,3)&(4,3)&(3,3)&(2,3)&(1,3)&color{red}{(0,3)}\
(0,2)&color{orange}{(1,2)}&(2,2)&(3,2)&(4,2)&(4,2)&(3,2)&(2,2)&color{orange}{(1,2)}&(0,2)\
(0,1)&(1,1)&color{orange}{(2,1)}&(3,1)&(4,1)&(4,1)&(3,1)&color{orange}{(2,1)}&(1,1)&(0,1)\
(0,0)&(1,0)&(2,0)&color{red}{(3,0)}&color{red}{(4,0)}&color{red}{(4,0)}&color{red}{(3,0)}&(2,0)&(1,0)&(0,0)end{matrix}
$$






share|improve this answer























  • Wow, this is awesome! I think $h + v geq n'$ can be simplified to $h+v>n'$, although I'm not sure if that helps the golfing logic at all.
    – Giuseppe
    Nov 6 at 22:20












  • @Giuseppe It could indeed be simplified that way if both conditions were tested. But in the code, the cases $hv=0$ and $hvneq0$ are separated. However, I'm actually testing the opposite condition ($n'>h+v$), which already is 1 byte shorter.
    – Arnauld
    Nov 6 at 22:29












  • @Giuseppe Your comment prompted me to have a closer look at the formula and I finally saved a byte by writing it a bit differently. :)
    – Arnauld
    Nov 6 at 22:41






  • 1




    heh, well your comment about $hv=0$ prompted me to go look at my port of your logic and save another couple of bytes!
    – Giuseppe
    Nov 6 at 22:44


















up vote
7
down vote














Charcoal, 5 bytes



GH*N#


My first answer with Charcoal!



Explanation:



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


Try it online!






share|improve this answer



















  • 2




    For those who prefer verbose Charcoal, that's PolygonHollow(:*, InputNumber(), "#");.
    – Neil
    Nov 6 at 18:51


















up vote
5
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


Alternative 12-byter.






share|improve this answer






























    up vote
    4
    down vote














    R, 122 117 115 bytes





    function(n){n=n-1
    m=matrix(0,y<-3*n+1,y)
    v=t(h<-(w=3*n/2)-abs(row(m)-1-w))
    m[h*v&h+v-n|h+v<n]=' '
    write(m,1,y,,"")}


    Try it online!



    Ports the logic from Arnauld's answer, specifically this revision in case there are further improvements. Another 2 bytes saved thanks to Arnauld's suggestion of inverting the logic!






    share|improve this answer























    • -2 bytes by doing it the other way around (I can't do h*v&h+v-n in JS because & is a bitwise operator; but it's a logical one in R, so that works).
      – Arnauld
      Nov 7 at 15:05










    • @Arnauld thanks!
      – Giuseppe
      Nov 7 at 15:39


















    up vote
    3
    down vote














    Python 2, 96 bytes





    a=b=n=input()
    while a>2-n-n:a-=1;b-=a/~-n+1;s=(-~b*' '+'#').ljust(n);print s+s[-1]*(n-2)+s[::-1]


    Try it online!






    share|improve this answer




























      up vote
      3
      down vote














      Python 2, 81 bytes





      a=d=n=input()-1
      while a<=n:print' '*a+'#'+' #'[a==n]*(3*n-a+~a)+'#';d-=1;a-=d/n+1


      Try it online!





      Python 2, 75 bytes





      a=d=n=input()-1
      while a<=n:print' '*a+`' `'[a==n]*(3*n-a+~a)`;d-=1;a-=d/n+1


      Try it online!



      If mixing output characters is OK.






      share|improve this answer






























        up vote
        3
        down vote













        Powershell, 91 bytes





        param($n)($s=' '*--$n+'#'*$n+'#')
        --$n..0+,0*$n+0..$n|%{' '*$_+"#$(' '*(3*$n-2*$_+2))#"}
        $s





        share|improve this answer




























          up vote
          2
          down vote














          PowerShell, 107 97 bytes





          param($n)($z=$n-1)..1+,0*$n+1..$z|%{" "*$_+"#"+($x=" "*($z-$_))+(" ","#")[!($_-$z)]*($n-2)+"$x#"}


          Try it online!



          If there was a cheap way to reverse the first half, this answer would feel a lot better. It builds the left half, then the core (which is either x #'s or spaces), then mirrors the left's logic to make the right. Fun fact, you don't need to copy over trailing white-space.



          Unrolled and explained:



          param($n)
          ($z=$n-1)..1 + ,0*$n + 1..$z |%{ #Range that repeats 0 n times in the middle
          " "*$_ + "#" +($x=" "*($z-$_)) + #Left side
          (" ","#")[!($_-$z)]*($n-2) + #Core that swaps when it's the first or last row
          "$x#"} #Right side which is left but backwards





          share|improve this answer






























            up vote
            2
            down vote














            C (clang), -DP=printf( -DF=for(i + 179 = 199 bytes





            i;*m="%*d%*dn";g(n){P"%*d",n,0);F=0;i<n-1;i++)P"%d",0);P "n");}
            f(n){g(n);F=1;i<n;i++)P m,n-i,0,n+i+i-1,0);F=0;i<n-2;i++)P m,1,0,3*n-3,0);F=n-1;i;i--)P m,n-i,0,n+i+i-1,0);g(n);}


            Try it online!



            Ungolfed:



            f(n){
            int i;
            printf("%*d",n,0);
            for(i=0;i<n-1;i++){
            printf("0");
            }
            printf("n");
            for(i=1;i<n;i++){
            printf("%*d%*dn",n-i,0,n+i+i-1,0);
            }
            for(i=0;i<n-2;i++){
            printf("0%*dn",n+n+n-3,0);
            }
            for(i=n-1;i>0;i--){
            printf("%*d%*dn",n-i,0,n+i+i-1,0);
            }
            printf("%*d",n,0);
            for(i=0;i<n-1;i++){
            printf("0");
            }
            }





            share|improve this answer























            • 180 bytes
              – ceilingcat
              Nov 8 at 12:08


















            up vote
            1
            down vote














            Python 2, 130 bytes





            def f(n):
            a=[' '*~-n+n*'#']
            b=[' '*(n-i-2)+'#'+' '*(n+2*i) +'#'for i in range(n-2)]
            return a+b+['#%*s'%(3*n-3,'#')]*n+b[::-1]+a


            Try it online!



            On mobile, so not incredibly golfed.






            share|improve this answer





















            • You can remove the space after (n+2*i).
              – Zacharý
              Nov 8 at 13:26


















            up vote
            1
            down vote













            Batch, 260 bytes



            @echo off
            set s=
            for /l %%i in (1,1,%1)do call set s= %%s%%
            echo %s% %s: =#%
            call:c %1,-1,3
            for /l %%i in (1,1,%1)do echo #%s:~2%%s%%s:~2%#
            call:c 3,1,%1
            echo %s% %s: =#%
            exit/b
            :c
            for /l %%i in (%*)do call echo %%s:~,%%i%%#%%s:~%%i%%%s%%%s:~%%i%%#


            Outputs two leading spaces on each line. Explanation: Batch has no string repetition operator, limited string slicing capability and requires separate statements to perform arithmetic. It was therefore golfiest to make up a string of the input length in spaces (Batch can at least translate these to #s for the top and bottom lines) and then slice from or to a specific position ranging from 3 to the length to generate the diagonals (this is what the last line of the script achieves).






            share|improve this answer




























              up vote
              1
              down vote














              Ruby, 96 bytes





              ->n{[*(n-=2).step(z=n*3+2,2),*[z]*n,*z.step(n,-2)].map{|x|([?#]*2*('# '[x<=>n]*x)).center(z+2)}}


              Try it online!



              Not very golfed yet. Might golf if I find the time.






              share|improve this answer




























                up vote
                1
                down vote














                Red, 171 bytes



                func[n][c:(a: n - 1)* 2 + n
                b: collect[loop c[keep pad/left copy"^/"c + 1]]s: 1x1 s/1: n
                foreach i[1x0 1 0x1 -1x1 -1x0 -1 0x-1 1x-1][loop a[b/(s/2)/(s/1): #"#"s: s + i]]b]


                Try it online!



                Explanation:



                Red
                f: func [ n ] [
                a: n - 1 ; size - 1
                c: a * 2 + n ; total size of widht / height
                b: collect [ ; create a block
                loop c [ ; composed of size - 1 rows
                keep pad/left copy "^/" c + 1 ; of empty lines of size c (and a newline)
                ]
                ]
                s: a * 1x0 + 1 ; starting coordinate
                foreach i [ 1x0 1 0x1 -1x1 -1x0 -1 0x-1 1x-1 ] [ ; for each offset for the 8 directions
                loop a [ ; repeat n - 1 times
                b/(s/2)/(s/1): #"#" ; set the array at current coordinate to "#"
                s: s + i ; next coordinate
                ]
                ]
                b ; return the block
                ]





                share|improve this answer






























                  up vote
                  1
                  down vote














                  APL (Dyalog Unicode), 46 bytesSBCS





                  (' '@~5 6∊⍨1⊥⊢∘,)⌺3 3⊢<(⍉⌽⌊⊢)⍣2∘(∘.+⍨∘⍳¯2+3×⊢)


                  This solution was provided by Adám - thanks!



                  Try it online!



                  My (almost) original solution:




                  APL (Dyalog Unicode), 61 bytesSBCS





                  (((⊃∘' #'¨1+5∘=+6∘=)⊢)1⊥⊢∘,)⌺3 3⊢<(((⊖⌊⊢)⌽⌊⊢)(∘.+⍨(⍳¯2+3×⊢)))


                  Try it online!



                  Thanks to Adám for his help!



                  The idea is to find the "diamond" that lies partly in the square and apply an edge-detect filter to "outline" the octagone.






                  share|improve this answer



















                  • 1




                    46: (' '@~5 6∊⍨1⊥⊢∘,)⌺3 3⊢<(⍉⌽⌊⊢)⍣2∘(∘.+⍨∘⍳¯2+3×⊢)
                    – Adám
                    Nov 7 at 13:51






                  • 1




                    You can't actually use Classic here because of . Rather count 1 byte/char by referring to SBCS as per Meta.
                    – Adám
                    Nov 7 at 13:52










                  • @Adám Thanks! I don't know how to edit the header, can you do it for me?
                    – Galen Ivanov
                    Nov 7 at 14:01










                  • What do you mean by editing the header?
                    – Adám
                    Nov 7 at 14:22






                  • 1




                    Edit and copy from here.
                    – Adám
                    Nov 7 at 14:40


















                  up vote
                  1
                  down vote













                  Perl 5, 201 197 188 187 186 bytes:



                  $a=<>;$b=3*$a-4;$c='$"x($e-$_)."#".$"x$f."#n"';$e=($b-$a)/2+1;$d=$"x$e."#"x$a.$/;$f=$a;print$d,(map{(eval$c,$f+=2)[0]}1..$a-2),("#".$"x$b."#n")x$a,(map{$f-=2;eval$c}reverse 1..$a-2),$d


                  Try it online!



                  Reads the size of the octagon from first line of STDIN.






                  share|improve this answer










                  New contributor




                  Nathan Mills is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.


















                  • Welcome to PPCG! You can probably shave off a few bytes here and there by using tricks found in this post.
                    – Mego
                    Nov 8 at 5:14










                  • @Mego Yep. I was able to save 4 bytes by using $" instead of " ".
                    – Nathan Mills
                    Nov 8 at 17:14


















                  up vote
                  0
                  down vote














                  C (gcc), 158 153 bytes




                  • Saved five bytes thanks to ceilingcat.


                  O,c,t,g;o(n){for(O=2*~-n,t=c=O+n;t--;puts(""))for(g=c;g--;)putchar(32+(!t|t>c-2?g>n-2&g<=O:t<n-1|t>O?t+O==g|t-O==g|c-g-t-n==n-1|c-g-t+n==3-n:!g|g>c-2));}


                  Try it online!






                  share|improve this answer























                  • @ceilingcat Thank you.
                    – Jonathan Frech
                    Nov 8 at 21:00


















                  up vote
                  0
                  down vote














                  Python 3, 224 bytes





                  n=int(input())
                  z=" "*(n-1)+"#"*n+" "*(n-1)
                  print(z)
                  for i in range(n-2):print(" "*(n-i-2)+"#"+" "*(i*2+n)+"#")
                  print((("#"+" "*(n*3-4)+"#n")*n)[:-1])
                  for i in range(n-3,-1,-1):print(" "*(n-i-2)+"#"+" "*(i*2+n)+"#")
                  print(z)


                  Try it online!






                  share|improve this answer








                  New contributor




                  glietz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.


















                    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
































                    18 Answers
                    18






                    active

                    oldest

                    votes








                    18 Answers
                    18






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes








                    up vote
                    20
                    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























                    • Surely this should be 5 bytes? Or do code golf challenges see bytes and characters as interchangeable
                      – Doug
                      Nov 7 at 17:10






                    • 3




                      @Doug: It is 3 bytes in 05ab1e's code page
                      – Emigna
                      Nov 7 at 17:11










                    • Oh, cool! Thanks for the docs link!
                      – Doug
                      Nov 7 at 17:58










                    • >:( damnit, adnan
                      – ASCII-only
                      18 hours ago















                    up vote
                    20
                    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























                    • Surely this should be 5 bytes? Or do code golf challenges see bytes and characters as interchangeable
                      – Doug
                      Nov 7 at 17:10






                    • 3




                      @Doug: It is 3 bytes in 05ab1e's code page
                      – Emigna
                      Nov 7 at 17:11










                    • Oh, cool! Thanks for the docs link!
                      – Doug
                      Nov 7 at 17:58










                    • >:( damnit, adnan
                      – ASCII-only
                      18 hours ago













                    up vote
                    20
                    down vote










                    up vote
                    20
                    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 Nov 6 at 18:29

























                    answered Nov 6 at 18:12









                    Emigna

                    44.6k432136




                    44.6k432136












                    • Surely this should be 5 bytes? Or do code golf challenges see bytes and characters as interchangeable
                      – Doug
                      Nov 7 at 17:10






                    • 3




                      @Doug: It is 3 bytes in 05ab1e's code page
                      – Emigna
                      Nov 7 at 17:11










                    • Oh, cool! Thanks for the docs link!
                      – Doug
                      Nov 7 at 17:58










                    • >:( damnit, adnan
                      – ASCII-only
                      18 hours ago


















                    • Surely this should be 5 bytes? Or do code golf challenges see bytes and characters as interchangeable
                      – Doug
                      Nov 7 at 17:10






                    • 3




                      @Doug: It is 3 bytes in 05ab1e's code page
                      – Emigna
                      Nov 7 at 17:11










                    • Oh, cool! Thanks for the docs link!
                      – Doug
                      Nov 7 at 17:58










                    • >:( damnit, adnan
                      – ASCII-only
                      18 hours ago
















                    Surely this should be 5 bytes? Or do code golf challenges see bytes and characters as interchangeable
                    – Doug
                    Nov 7 at 17:10




                    Surely this should be 5 bytes? Or do code golf challenges see bytes and characters as interchangeable
                    – Doug
                    Nov 7 at 17:10




                    3




                    3




                    @Doug: It is 3 bytes in 05ab1e's code page
                    – Emigna
                    Nov 7 at 17:11




                    @Doug: It is 3 bytes in 05ab1e's code page
                    – Emigna
                    Nov 7 at 17:11












                    Oh, cool! Thanks for the docs link!
                    – Doug
                    Nov 7 at 17:58




                    Oh, cool! Thanks for the docs link!
                    – Doug
                    Nov 7 at 17:58












                    >:( damnit, adnan
                    – ASCII-only
                    18 hours ago




                    >:( damnit, adnan
                    – ASCII-only
                    18 hours ago










                    up vote
                    10
                    down vote













                    JavaScript (ES6), 114 106 105 104 103 bytes





                    n=>(g=x=>v=x*2>w?w-x:x,F=x=>~y?`# 
                    `[~x?(h=g(x--))*g(y)>0&h+v!=n|n>h+v:(y--,x=w,2)]+F(x):'')(y=w=--n*3)


                    Try it online!



                    How?



                    This builds the output character by character.



                    Given the input $n$, we compute:



                    $$n'=n-1\w=3n'$$



                    For each character at $(x,y)$, we compute $(h,v)$:



                    $$h=w/2-left|x-w/2right|\v=w/2-left|y-w/2right|$$



                    The cells belonging to the octagon satisfy one of the following conditions:




                    • ($h=0$ OR $v=0$) AND $h+vge n'$ (in red below)


                    • $h+v=n'$ (in orange below)


                    For example, with $n=4$ (and $n'=3$):



                    $$begin{matrix}(0,0)&(1,0)&(2,0)&color{red}{(3,0)}&color{red}{(4,0)}&color{red}{(4,0)}&color{red}{(3,0)}&(2,0)&(1,0)&(0,0)\
                    (0,1)&(1,1)&color{orange}{(2,1)}&(3,1)&(4,1)&(4,1)&(3,1)&color{orange}{(2,1)}&(1,1)&(0,1)\
                    (0,2)&color{orange}{(1,2)}&(2,2)&(3,2)&(4,2)&(4,2)&(3,2)&(2,2)&color{orange}{(1,2)}&(0,2)\
                    color{red}{(0,3)}&(1,3)&(2,3)&(3,3)&(4,3)&(4,3)&(3,3)&(2,3)&(1,3)&color{red}{(0,3)}\
                    color{red}{(0,4)}&(1,4)&(2,4)&(3,4)&(4,4)&(4,4)&(3,4)&(2,4)&(1,4)&color{red}{(0,4)}\
                    color{red}{(0,4)}&(1,4)&(2,4)&(3,4)&(4,4)&(4,4)&(3,4)&(2,4)&(1,4)&color{red}{(0,4)}\
                    color{red}{(0,3)}&(1,3)&(2,3)&(3,3)&(4,3)&(4,3)&(3,3)&(2,3)&(1,3)&color{red}{(0,3)}\
                    (0,2)&color{orange}{(1,2)}&(2,2)&(3,2)&(4,2)&(4,2)&(3,2)&(2,2)&color{orange}{(1,2)}&(0,2)\
                    (0,1)&(1,1)&color{orange}{(2,1)}&(3,1)&(4,1)&(4,1)&(3,1)&color{orange}{(2,1)}&(1,1)&(0,1)\
                    (0,0)&(1,0)&(2,0)&color{red}{(3,0)}&color{red}{(4,0)}&color{red}{(4,0)}&color{red}{(3,0)}&(2,0)&(1,0)&(0,0)end{matrix}
                    $$






                    share|improve this answer























                    • Wow, this is awesome! I think $h + v geq n'$ can be simplified to $h+v>n'$, although I'm not sure if that helps the golfing logic at all.
                      – Giuseppe
                      Nov 6 at 22:20












                    • @Giuseppe It could indeed be simplified that way if both conditions were tested. But in the code, the cases $hv=0$ and $hvneq0$ are separated. However, I'm actually testing the opposite condition ($n'>h+v$), which already is 1 byte shorter.
                      – Arnauld
                      Nov 6 at 22:29












                    • @Giuseppe Your comment prompted me to have a closer look at the formula and I finally saved a byte by writing it a bit differently. :)
                      – Arnauld
                      Nov 6 at 22:41






                    • 1




                      heh, well your comment about $hv=0$ prompted me to go look at my port of your logic and save another couple of bytes!
                      – Giuseppe
                      Nov 6 at 22:44















                    up vote
                    10
                    down vote













                    JavaScript (ES6), 114 106 105 104 103 bytes





                    n=>(g=x=>v=x*2>w?w-x:x,F=x=>~y?`# 
                    `[~x?(h=g(x--))*g(y)>0&h+v!=n|n>h+v:(y--,x=w,2)]+F(x):'')(y=w=--n*3)


                    Try it online!



                    How?



                    This builds the output character by character.



                    Given the input $n$, we compute:



                    $$n'=n-1\w=3n'$$



                    For each character at $(x,y)$, we compute $(h,v)$:



                    $$h=w/2-left|x-w/2right|\v=w/2-left|y-w/2right|$$



                    The cells belonging to the octagon satisfy one of the following conditions:




                    • ($h=0$ OR $v=0$) AND $h+vge n'$ (in red below)


                    • $h+v=n'$ (in orange below)


                    For example, with $n=4$ (and $n'=3$):



                    $$begin{matrix}(0,0)&(1,0)&(2,0)&color{red}{(3,0)}&color{red}{(4,0)}&color{red}{(4,0)}&color{red}{(3,0)}&(2,0)&(1,0)&(0,0)\
                    (0,1)&(1,1)&color{orange}{(2,1)}&(3,1)&(4,1)&(4,1)&(3,1)&color{orange}{(2,1)}&(1,1)&(0,1)\
                    (0,2)&color{orange}{(1,2)}&(2,2)&(3,2)&(4,2)&(4,2)&(3,2)&(2,2)&color{orange}{(1,2)}&(0,2)\
                    color{red}{(0,3)}&(1,3)&(2,3)&(3,3)&(4,3)&(4,3)&(3,3)&(2,3)&(1,3)&color{red}{(0,3)}\
                    color{red}{(0,4)}&(1,4)&(2,4)&(3,4)&(4,4)&(4,4)&(3,4)&(2,4)&(1,4)&color{red}{(0,4)}\
                    color{red}{(0,4)}&(1,4)&(2,4)&(3,4)&(4,4)&(4,4)&(3,4)&(2,4)&(1,4)&color{red}{(0,4)}\
                    color{red}{(0,3)}&(1,3)&(2,3)&(3,3)&(4,3)&(4,3)&(3,3)&(2,3)&(1,3)&color{red}{(0,3)}\
                    (0,2)&color{orange}{(1,2)}&(2,2)&(3,2)&(4,2)&(4,2)&(3,2)&(2,2)&color{orange}{(1,2)}&(0,2)\
                    (0,1)&(1,1)&color{orange}{(2,1)}&(3,1)&(4,1)&(4,1)&(3,1)&color{orange}{(2,1)}&(1,1)&(0,1)\
                    (0,0)&(1,0)&(2,0)&color{red}{(3,0)}&color{red}{(4,0)}&color{red}{(4,0)}&color{red}{(3,0)}&(2,0)&(1,0)&(0,0)end{matrix}
                    $$






                    share|improve this answer























                    • Wow, this is awesome! I think $h + v geq n'$ can be simplified to $h+v>n'$, although I'm not sure if that helps the golfing logic at all.
                      – Giuseppe
                      Nov 6 at 22:20












                    • @Giuseppe It could indeed be simplified that way if both conditions were tested. But in the code, the cases $hv=0$ and $hvneq0$ are separated. However, I'm actually testing the opposite condition ($n'>h+v$), which already is 1 byte shorter.
                      – Arnauld
                      Nov 6 at 22:29












                    • @Giuseppe Your comment prompted me to have a closer look at the formula and I finally saved a byte by writing it a bit differently. :)
                      – Arnauld
                      Nov 6 at 22:41






                    • 1




                      heh, well your comment about $hv=0$ prompted me to go look at my port of your logic and save another couple of bytes!
                      – Giuseppe
                      Nov 6 at 22:44













                    up vote
                    10
                    down vote










                    up vote
                    10
                    down vote









                    JavaScript (ES6), 114 106 105 104 103 bytes





                    n=>(g=x=>v=x*2>w?w-x:x,F=x=>~y?`# 
                    `[~x?(h=g(x--))*g(y)>0&h+v!=n|n>h+v:(y--,x=w,2)]+F(x):'')(y=w=--n*3)


                    Try it online!



                    How?



                    This builds the output character by character.



                    Given the input $n$, we compute:



                    $$n'=n-1\w=3n'$$



                    For each character at $(x,y)$, we compute $(h,v)$:



                    $$h=w/2-left|x-w/2right|\v=w/2-left|y-w/2right|$$



                    The cells belonging to the octagon satisfy one of the following conditions:




                    • ($h=0$ OR $v=0$) AND $h+vge n'$ (in red below)


                    • $h+v=n'$ (in orange below)


                    For example, with $n=4$ (and $n'=3$):



                    $$begin{matrix}(0,0)&(1,0)&(2,0)&color{red}{(3,0)}&color{red}{(4,0)}&color{red}{(4,0)}&color{red}{(3,0)}&(2,0)&(1,0)&(0,0)\
                    (0,1)&(1,1)&color{orange}{(2,1)}&(3,1)&(4,1)&(4,1)&(3,1)&color{orange}{(2,1)}&(1,1)&(0,1)\
                    (0,2)&color{orange}{(1,2)}&(2,2)&(3,2)&(4,2)&(4,2)&(3,2)&(2,2)&color{orange}{(1,2)}&(0,2)\
                    color{red}{(0,3)}&(1,3)&(2,3)&(3,3)&(4,3)&(4,3)&(3,3)&(2,3)&(1,3)&color{red}{(0,3)}\
                    color{red}{(0,4)}&(1,4)&(2,4)&(3,4)&(4,4)&(4,4)&(3,4)&(2,4)&(1,4)&color{red}{(0,4)}\
                    color{red}{(0,4)}&(1,4)&(2,4)&(3,4)&(4,4)&(4,4)&(3,4)&(2,4)&(1,4)&color{red}{(0,4)}\
                    color{red}{(0,3)}&(1,3)&(2,3)&(3,3)&(4,3)&(4,3)&(3,3)&(2,3)&(1,3)&color{red}{(0,3)}\
                    (0,2)&color{orange}{(1,2)}&(2,2)&(3,2)&(4,2)&(4,2)&(3,2)&(2,2)&color{orange}{(1,2)}&(0,2)\
                    (0,1)&(1,1)&color{orange}{(2,1)}&(3,1)&(4,1)&(4,1)&(3,1)&color{orange}{(2,1)}&(1,1)&(0,1)\
                    (0,0)&(1,0)&(2,0)&color{red}{(3,0)}&color{red}{(4,0)}&color{red}{(4,0)}&color{red}{(3,0)}&(2,0)&(1,0)&(0,0)end{matrix}
                    $$






                    share|improve this answer














                    JavaScript (ES6), 114 106 105 104 103 bytes





                    n=>(g=x=>v=x*2>w?w-x:x,F=x=>~y?`# 
                    `[~x?(h=g(x--))*g(y)>0&h+v!=n|n>h+v:(y--,x=w,2)]+F(x):'')(y=w=--n*3)


                    Try it online!



                    How?



                    This builds the output character by character.



                    Given the input $n$, we compute:



                    $$n'=n-1\w=3n'$$



                    For each character at $(x,y)$, we compute $(h,v)$:



                    $$h=w/2-left|x-w/2right|\v=w/2-left|y-w/2right|$$



                    The cells belonging to the octagon satisfy one of the following conditions:




                    • ($h=0$ OR $v=0$) AND $h+vge n'$ (in red below)


                    • $h+v=n'$ (in orange below)


                    For example, with $n=4$ (and $n'=3$):



                    $$begin{matrix}(0,0)&(1,0)&(2,0)&color{red}{(3,0)}&color{red}{(4,0)}&color{red}{(4,0)}&color{red}{(3,0)}&(2,0)&(1,0)&(0,0)\
                    (0,1)&(1,1)&color{orange}{(2,1)}&(3,1)&(4,1)&(4,1)&(3,1)&color{orange}{(2,1)}&(1,1)&(0,1)\
                    (0,2)&color{orange}{(1,2)}&(2,2)&(3,2)&(4,2)&(4,2)&(3,2)&(2,2)&color{orange}{(1,2)}&(0,2)\
                    color{red}{(0,3)}&(1,3)&(2,3)&(3,3)&(4,3)&(4,3)&(3,3)&(2,3)&(1,3)&color{red}{(0,3)}\
                    color{red}{(0,4)}&(1,4)&(2,4)&(3,4)&(4,4)&(4,4)&(3,4)&(2,4)&(1,4)&color{red}{(0,4)}\
                    color{red}{(0,4)}&(1,4)&(2,4)&(3,4)&(4,4)&(4,4)&(3,4)&(2,4)&(1,4)&color{red}{(0,4)}\
                    color{red}{(0,3)}&(1,3)&(2,3)&(3,3)&(4,3)&(4,3)&(3,3)&(2,3)&(1,3)&color{red}{(0,3)}\
                    (0,2)&color{orange}{(1,2)}&(2,2)&(3,2)&(4,2)&(4,2)&(3,2)&(2,2)&color{orange}{(1,2)}&(0,2)\
                    (0,1)&(1,1)&color{orange}{(2,1)}&(3,1)&(4,1)&(4,1)&(3,1)&color{orange}{(2,1)}&(1,1)&(0,1)\
                    (0,0)&(1,0)&(2,0)&color{red}{(3,0)}&color{red}{(4,0)}&color{red}{(4,0)}&color{red}{(3,0)}&(2,0)&(1,0)&(0,0)end{matrix}
                    $$







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 6 at 22:38

























                    answered Nov 6 at 20:09









                    Arnauld

                    68.1k584288




                    68.1k584288












                    • Wow, this is awesome! I think $h + v geq n'$ can be simplified to $h+v>n'$, although I'm not sure if that helps the golfing logic at all.
                      – Giuseppe
                      Nov 6 at 22:20












                    • @Giuseppe It could indeed be simplified that way if both conditions were tested. But in the code, the cases $hv=0$ and $hvneq0$ are separated. However, I'm actually testing the opposite condition ($n'>h+v$), which already is 1 byte shorter.
                      – Arnauld
                      Nov 6 at 22:29












                    • @Giuseppe Your comment prompted me to have a closer look at the formula and I finally saved a byte by writing it a bit differently. :)
                      – Arnauld
                      Nov 6 at 22:41






                    • 1




                      heh, well your comment about $hv=0$ prompted me to go look at my port of your logic and save another couple of bytes!
                      – Giuseppe
                      Nov 6 at 22:44


















                    • Wow, this is awesome! I think $h + v geq n'$ can be simplified to $h+v>n'$, although I'm not sure if that helps the golfing logic at all.
                      – Giuseppe
                      Nov 6 at 22:20












                    • @Giuseppe It could indeed be simplified that way if both conditions were tested. But in the code, the cases $hv=0$ and $hvneq0$ are separated. However, I'm actually testing the opposite condition ($n'>h+v$), which already is 1 byte shorter.
                      – Arnauld
                      Nov 6 at 22:29












                    • @Giuseppe Your comment prompted me to have a closer look at the formula and I finally saved a byte by writing it a bit differently. :)
                      – Arnauld
                      Nov 6 at 22:41






                    • 1




                      heh, well your comment about $hv=0$ prompted me to go look at my port of your logic and save another couple of bytes!
                      – Giuseppe
                      Nov 6 at 22:44
















                    Wow, this is awesome! I think $h + v geq n'$ can be simplified to $h+v>n'$, although I'm not sure if that helps the golfing logic at all.
                    – Giuseppe
                    Nov 6 at 22:20






                    Wow, this is awesome! I think $h + v geq n'$ can be simplified to $h+v>n'$, although I'm not sure if that helps the golfing logic at all.
                    – Giuseppe
                    Nov 6 at 22:20














                    @Giuseppe It could indeed be simplified that way if both conditions were tested. But in the code, the cases $hv=0$ and $hvneq0$ are separated. However, I'm actually testing the opposite condition ($n'>h+v$), which already is 1 byte shorter.
                    – Arnauld
                    Nov 6 at 22:29






                    @Giuseppe It could indeed be simplified that way if both conditions were tested. But in the code, the cases $hv=0$ and $hvneq0$ are separated. However, I'm actually testing the opposite condition ($n'>h+v$), which already is 1 byte shorter.
                    – Arnauld
                    Nov 6 at 22:29














                    @Giuseppe Your comment prompted me to have a closer look at the formula and I finally saved a byte by writing it a bit differently. :)
                    – Arnauld
                    Nov 6 at 22:41




                    @Giuseppe Your comment prompted me to have a closer look at the formula and I finally saved a byte by writing it a bit differently. :)
                    – Arnauld
                    Nov 6 at 22:41




                    1




                    1




                    heh, well your comment about $hv=0$ prompted me to go look at my port of your logic and save another couple of bytes!
                    – Giuseppe
                    Nov 6 at 22:44




                    heh, well your comment about $hv=0$ prompted me to go look at my port of your logic and save another couple of bytes!
                    – Giuseppe
                    Nov 6 at 22:44










                    up vote
                    7
                    down vote














                    Charcoal, 5 bytes



                    GH*N#


                    My first answer with Charcoal!



                    Explanation:



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


                    Try it online!






                    share|improve this answer



















                    • 2




                      For those who prefer verbose Charcoal, that's PolygonHollow(:*, InputNumber(), "#");.
                      – Neil
                      Nov 6 at 18:51















                    up vote
                    7
                    down vote














                    Charcoal, 5 bytes



                    GH*N#


                    My first answer with Charcoal!



                    Explanation:



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


                    Try it online!






                    share|improve this answer



















                    • 2




                      For those who prefer verbose Charcoal, that's PolygonHollow(:*, InputNumber(), "#");.
                      – Neil
                      Nov 6 at 18:51













                    up vote
                    7
                    down vote










                    up vote
                    7
                    down vote










                    Charcoal, 5 bytes



                    GH*N#


                    My first answer with Charcoal!



                    Explanation:



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


                    Try it online!






                    share|improve this answer















                    Charcoal, 5 bytes



                    GH*N#


                    My first answer with Charcoal!



                    Explanation:



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


                    Try it online!







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 8 at 13:36

























                    answered Nov 6 at 18:25









                    Cowabunghole

                    953418




                    953418








                    • 2




                      For those who prefer verbose Charcoal, that's PolygonHollow(:*, InputNumber(), "#");.
                      – Neil
                      Nov 6 at 18:51














                    • 2




                      For those who prefer verbose Charcoal, that's PolygonHollow(:*, InputNumber(), "#");.
                      – Neil
                      Nov 6 at 18:51








                    2




                    2




                    For those who prefer verbose Charcoal, that's PolygonHollow(:*, InputNumber(), "#");.
                    – Neil
                    Nov 6 at 18:51




                    For those who prefer verbose Charcoal, that's PolygonHollow(:*, InputNumber(), "#");.
                    – Neil
                    Nov 6 at 18:51










                    up vote
                    5
                    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


                    Alternative 12-byter.






                    share|improve this answer



























                      up vote
                      5
                      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


                      Alternative 12-byter.






                      share|improve this answer

























                        up vote
                        5
                        down vote










                        up vote
                        5
                        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


                        Alternative 12-byter.






                        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


                        Alternative 12-byter.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Nov 6 at 18:55

























                        answered Nov 6 at 17:56









                        dzaima

                        13.9k21653




                        13.9k21653






















                            up vote
                            4
                            down vote














                            R, 122 117 115 bytes





                            function(n){n=n-1
                            m=matrix(0,y<-3*n+1,y)
                            v=t(h<-(w=3*n/2)-abs(row(m)-1-w))
                            m[h*v&h+v-n|h+v<n]=' '
                            write(m,1,y,,"")}


                            Try it online!



                            Ports the logic from Arnauld's answer, specifically this revision in case there are further improvements. Another 2 bytes saved thanks to Arnauld's suggestion of inverting the logic!






                            share|improve this answer























                            • -2 bytes by doing it the other way around (I can't do h*v&h+v-n in JS because & is a bitwise operator; but it's a logical one in R, so that works).
                              – Arnauld
                              Nov 7 at 15:05










                            • @Arnauld thanks!
                              – Giuseppe
                              Nov 7 at 15:39















                            up vote
                            4
                            down vote














                            R, 122 117 115 bytes





                            function(n){n=n-1
                            m=matrix(0,y<-3*n+1,y)
                            v=t(h<-(w=3*n/2)-abs(row(m)-1-w))
                            m[h*v&h+v-n|h+v<n]=' '
                            write(m,1,y,,"")}


                            Try it online!



                            Ports the logic from Arnauld's answer, specifically this revision in case there are further improvements. Another 2 bytes saved thanks to Arnauld's suggestion of inverting the logic!






                            share|improve this answer























                            • -2 bytes by doing it the other way around (I can't do h*v&h+v-n in JS because & is a bitwise operator; but it's a logical one in R, so that works).
                              – Arnauld
                              Nov 7 at 15:05










                            • @Arnauld thanks!
                              – Giuseppe
                              Nov 7 at 15:39













                            up vote
                            4
                            down vote










                            up vote
                            4
                            down vote










                            R, 122 117 115 bytes





                            function(n){n=n-1
                            m=matrix(0,y<-3*n+1,y)
                            v=t(h<-(w=3*n/2)-abs(row(m)-1-w))
                            m[h*v&h+v-n|h+v<n]=' '
                            write(m,1,y,,"")}


                            Try it online!



                            Ports the logic from Arnauld's answer, specifically this revision in case there are further improvements. Another 2 bytes saved thanks to Arnauld's suggestion of inverting the logic!






                            share|improve this answer















                            R, 122 117 115 bytes





                            function(n){n=n-1
                            m=matrix(0,y<-3*n+1,y)
                            v=t(h<-(w=3*n/2)-abs(row(m)-1-w))
                            m[h*v&h+v-n|h+v<n]=' '
                            write(m,1,y,,"")}


                            Try it online!



                            Ports the logic from Arnauld's answer, specifically this revision in case there are further improvements. Another 2 bytes saved thanks to Arnauld's suggestion of inverting the logic!







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 7 at 15:39

























                            answered Nov 6 at 18:33









                            Giuseppe

                            15.7k31051




                            15.7k31051












                            • -2 bytes by doing it the other way around (I can't do h*v&h+v-n in JS because & is a bitwise operator; but it's a logical one in R, so that works).
                              – Arnauld
                              Nov 7 at 15:05










                            • @Arnauld thanks!
                              – Giuseppe
                              Nov 7 at 15:39


















                            • -2 bytes by doing it the other way around (I can't do h*v&h+v-n in JS because & is a bitwise operator; but it's a logical one in R, so that works).
                              – Arnauld
                              Nov 7 at 15:05










                            • @Arnauld thanks!
                              – Giuseppe
                              Nov 7 at 15:39
















                            -2 bytes by doing it the other way around (I can't do h*v&h+v-n in JS because & is a bitwise operator; but it's a logical one in R, so that works).
                            – Arnauld
                            Nov 7 at 15:05




                            -2 bytes by doing it the other way around (I can't do h*v&h+v-n in JS because & is a bitwise operator; but it's a logical one in R, so that works).
                            – Arnauld
                            Nov 7 at 15:05












                            @Arnauld thanks!
                            – Giuseppe
                            Nov 7 at 15:39




                            @Arnauld thanks!
                            – Giuseppe
                            Nov 7 at 15:39










                            up vote
                            3
                            down vote














                            Python 2, 96 bytes





                            a=b=n=input()
                            while a>2-n-n:a-=1;b-=a/~-n+1;s=(-~b*' '+'#').ljust(n);print s+s[-1]*(n-2)+s[::-1]


                            Try it online!






                            share|improve this answer

























                              up vote
                              3
                              down vote














                              Python 2, 96 bytes





                              a=b=n=input()
                              while a>2-n-n:a-=1;b-=a/~-n+1;s=(-~b*' '+'#').ljust(n);print s+s[-1]*(n-2)+s[::-1]


                              Try it online!






                              share|improve this answer























                                up vote
                                3
                                down vote










                                up vote
                                3
                                down vote










                                Python 2, 96 bytes





                                a=b=n=input()
                                while a>2-n-n:a-=1;b-=a/~-n+1;s=(-~b*' '+'#').ljust(n);print s+s[-1]*(n-2)+s[::-1]


                                Try it online!






                                share|improve this answer













                                Python 2, 96 bytes





                                a=b=n=input()
                                while a>2-n-n:a-=1;b-=a/~-n+1;s=(-~b*' '+'#').ljust(n);print s+s[-1]*(n-2)+s[::-1]


                                Try it online!







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Nov 6 at 22:03









                                Lynn

                                49k694223




                                49k694223






















                                    up vote
                                    3
                                    down vote














                                    Python 2, 81 bytes





                                    a=d=n=input()-1
                                    while a<=n:print' '*a+'#'+' #'[a==n]*(3*n-a+~a)+'#';d-=1;a-=d/n+1


                                    Try it online!





                                    Python 2, 75 bytes





                                    a=d=n=input()-1
                                    while a<=n:print' '*a+`' `'[a==n]*(3*n-a+~a)`;d-=1;a-=d/n+1


                                    Try it online!



                                    If mixing output characters is OK.






                                    share|improve this answer



























                                      up vote
                                      3
                                      down vote














                                      Python 2, 81 bytes





                                      a=d=n=input()-1
                                      while a<=n:print' '*a+'#'+' #'[a==n]*(3*n-a+~a)+'#';d-=1;a-=d/n+1


                                      Try it online!





                                      Python 2, 75 bytes





                                      a=d=n=input()-1
                                      while a<=n:print' '*a+`' `'[a==n]*(3*n-a+~a)`;d-=1;a-=d/n+1


                                      Try it online!



                                      If mixing output characters is OK.






                                      share|improve this answer

























                                        up vote
                                        3
                                        down vote










                                        up vote
                                        3
                                        down vote










                                        Python 2, 81 bytes





                                        a=d=n=input()-1
                                        while a<=n:print' '*a+'#'+' #'[a==n]*(3*n-a+~a)+'#';d-=1;a-=d/n+1


                                        Try it online!





                                        Python 2, 75 bytes





                                        a=d=n=input()-1
                                        while a<=n:print' '*a+`' `'[a==n]*(3*n-a+~a)`;d-=1;a-=d/n+1


                                        Try it online!



                                        If mixing output characters is OK.






                                        share|improve this answer















                                        Python 2, 81 bytes





                                        a=d=n=input()-1
                                        while a<=n:print' '*a+'#'+' #'[a==n]*(3*n-a+~a)+'#';d-=1;a-=d/n+1


                                        Try it online!





                                        Python 2, 75 bytes





                                        a=d=n=input()-1
                                        while a<=n:print' '*a+`' `'[a==n]*(3*n-a+~a)`;d-=1;a-=d/n+1


                                        Try it online!



                                        If mixing output characters is OK.







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Nov 6 at 23:58

























                                        answered Nov 6 at 23:49









                                        xnor

                                        88.3k17183434




                                        88.3k17183434






















                                            up vote
                                            3
                                            down vote













                                            Powershell, 91 bytes





                                            param($n)($s=' '*--$n+'#'*$n+'#')
                                            --$n..0+,0*$n+0..$n|%{' '*$_+"#$(' '*(3*$n-2*$_+2))#"}
                                            $s





                                            share|improve this answer

























                                              up vote
                                              3
                                              down vote













                                              Powershell, 91 bytes





                                              param($n)($s=' '*--$n+'#'*$n+'#')
                                              --$n..0+,0*$n+0..$n|%{' '*$_+"#$(' '*(3*$n-2*$_+2))#"}
                                              $s





                                              share|improve this answer























                                                up vote
                                                3
                                                down vote










                                                up vote
                                                3
                                                down vote









                                                Powershell, 91 bytes





                                                param($n)($s=' '*--$n+'#'*$n+'#')
                                                --$n..0+,0*$n+0..$n|%{' '*$_+"#$(' '*(3*$n-2*$_+2))#"}
                                                $s





                                                share|improve this answer












                                                Powershell, 91 bytes





                                                param($n)($s=' '*--$n+'#'*$n+'#')
                                                --$n..0+,0*$n+0..$n|%{' '*$_+"#$(' '*(3*$n-2*$_+2))#"}
                                                $s






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Nov 7 at 7:37









                                                mazzy

                                                1,665312




                                                1,665312






















                                                    up vote
                                                    2
                                                    down vote














                                                    PowerShell, 107 97 bytes





                                                    param($n)($z=$n-1)..1+,0*$n+1..$z|%{" "*$_+"#"+($x=" "*($z-$_))+(" ","#")[!($_-$z)]*($n-2)+"$x#"}


                                                    Try it online!



                                                    If there was a cheap way to reverse the first half, this answer would feel a lot better. It builds the left half, then the core (which is either x #'s or spaces), then mirrors the left's logic to make the right. Fun fact, you don't need to copy over trailing white-space.



                                                    Unrolled and explained:



                                                    param($n)
                                                    ($z=$n-1)..1 + ,0*$n + 1..$z |%{ #Range that repeats 0 n times in the middle
                                                    " "*$_ + "#" +($x=" "*($z-$_)) + #Left side
                                                    (" ","#")[!($_-$z)]*($n-2) + #Core that swaps when it's the first or last row
                                                    "$x#"} #Right side which is left but backwards





                                                    share|improve this answer



























                                                      up vote
                                                      2
                                                      down vote














                                                      PowerShell, 107 97 bytes





                                                      param($n)($z=$n-1)..1+,0*$n+1..$z|%{" "*$_+"#"+($x=" "*($z-$_))+(" ","#")[!($_-$z)]*($n-2)+"$x#"}


                                                      Try it online!



                                                      If there was a cheap way to reverse the first half, this answer would feel a lot better. It builds the left half, then the core (which is either x #'s or spaces), then mirrors the left's logic to make the right. Fun fact, you don't need to copy over trailing white-space.



                                                      Unrolled and explained:



                                                      param($n)
                                                      ($z=$n-1)..1 + ,0*$n + 1..$z |%{ #Range that repeats 0 n times in the middle
                                                      " "*$_ + "#" +($x=" "*($z-$_)) + #Left side
                                                      (" ","#")[!($_-$z)]*($n-2) + #Core that swaps when it's the first or last row
                                                      "$x#"} #Right side which is left but backwards





                                                      share|improve this answer

























                                                        up vote
                                                        2
                                                        down vote










                                                        up vote
                                                        2
                                                        down vote










                                                        PowerShell, 107 97 bytes





                                                        param($n)($z=$n-1)..1+,0*$n+1..$z|%{" "*$_+"#"+($x=" "*($z-$_))+(" ","#")[!($_-$z)]*($n-2)+"$x#"}


                                                        Try it online!



                                                        If there was a cheap way to reverse the first half, this answer would feel a lot better. It builds the left half, then the core (which is either x #'s or spaces), then mirrors the left's logic to make the right. Fun fact, you don't need to copy over trailing white-space.



                                                        Unrolled and explained:



                                                        param($n)
                                                        ($z=$n-1)..1 + ,0*$n + 1..$z |%{ #Range that repeats 0 n times in the middle
                                                        " "*$_ + "#" +($x=" "*($z-$_)) + #Left side
                                                        (" ","#")[!($_-$z)]*($n-2) + #Core that swaps when it's the first or last row
                                                        "$x#"} #Right side which is left but backwards





                                                        share|improve this answer















                                                        PowerShell, 107 97 bytes





                                                        param($n)($z=$n-1)..1+,0*$n+1..$z|%{" "*$_+"#"+($x=" "*($z-$_))+(" ","#")[!($_-$z)]*($n-2)+"$x#"}


                                                        Try it online!



                                                        If there was a cheap way to reverse the first half, this answer would feel a lot better. It builds the left half, then the core (which is either x #'s or spaces), then mirrors the left's logic to make the right. Fun fact, you don't need to copy over trailing white-space.



                                                        Unrolled and explained:



                                                        param($n)
                                                        ($z=$n-1)..1 + ,0*$n + 1..$z |%{ #Range that repeats 0 n times in the middle
                                                        " "*$_ + "#" +($x=" "*($z-$_)) + #Left side
                                                        (" ","#")[!($_-$z)]*($n-2) + #Core that swaps when it's the first or last row
                                                        "$x#"} #Right side which is left but backwards






                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Nov 7 at 2:13

























                                                        answered Nov 7 at 0:38









                                                        Veskah

                                                        66311




                                                        66311






















                                                            up vote
                                                            2
                                                            down vote














                                                            C (clang), -DP=printf( -DF=for(i + 179 = 199 bytes





                                                            i;*m="%*d%*dn";g(n){P"%*d",n,0);F=0;i<n-1;i++)P"%d",0);P "n");}
                                                            f(n){g(n);F=1;i<n;i++)P m,n-i,0,n+i+i-1,0);F=0;i<n-2;i++)P m,1,0,3*n-3,0);F=n-1;i;i--)P m,n-i,0,n+i+i-1,0);g(n);}


                                                            Try it online!



                                                            Ungolfed:



                                                            f(n){
                                                            int i;
                                                            printf("%*d",n,0);
                                                            for(i=0;i<n-1;i++){
                                                            printf("0");
                                                            }
                                                            printf("n");
                                                            for(i=1;i<n;i++){
                                                            printf("%*d%*dn",n-i,0,n+i+i-1,0);
                                                            }
                                                            for(i=0;i<n-2;i++){
                                                            printf("0%*dn",n+n+n-3,0);
                                                            }
                                                            for(i=n-1;i>0;i--){
                                                            printf("%*d%*dn",n-i,0,n+i+i-1,0);
                                                            }
                                                            printf("%*d",n,0);
                                                            for(i=0;i<n-1;i++){
                                                            printf("0");
                                                            }
                                                            }





                                                            share|improve this answer























                                                            • 180 bytes
                                                              – ceilingcat
                                                              Nov 8 at 12:08















                                                            up vote
                                                            2
                                                            down vote














                                                            C (clang), -DP=printf( -DF=for(i + 179 = 199 bytes





                                                            i;*m="%*d%*dn";g(n){P"%*d",n,0);F=0;i<n-1;i++)P"%d",0);P "n");}
                                                            f(n){g(n);F=1;i<n;i++)P m,n-i,0,n+i+i-1,0);F=0;i<n-2;i++)P m,1,0,3*n-3,0);F=n-1;i;i--)P m,n-i,0,n+i+i-1,0);g(n);}


                                                            Try it online!



                                                            Ungolfed:



                                                            f(n){
                                                            int i;
                                                            printf("%*d",n,0);
                                                            for(i=0;i<n-1;i++){
                                                            printf("0");
                                                            }
                                                            printf("n");
                                                            for(i=1;i<n;i++){
                                                            printf("%*d%*dn",n-i,0,n+i+i-1,0);
                                                            }
                                                            for(i=0;i<n-2;i++){
                                                            printf("0%*dn",n+n+n-3,0);
                                                            }
                                                            for(i=n-1;i>0;i--){
                                                            printf("%*d%*dn",n-i,0,n+i+i-1,0);
                                                            }
                                                            printf("%*d",n,0);
                                                            for(i=0;i<n-1;i++){
                                                            printf("0");
                                                            }
                                                            }





                                                            share|improve this answer























                                                            • 180 bytes
                                                              – ceilingcat
                                                              Nov 8 at 12:08













                                                            up vote
                                                            2
                                                            down vote










                                                            up vote
                                                            2
                                                            down vote










                                                            C (clang), -DP=printf( -DF=for(i + 179 = 199 bytes





                                                            i;*m="%*d%*dn";g(n){P"%*d",n,0);F=0;i<n-1;i++)P"%d",0);P "n");}
                                                            f(n){g(n);F=1;i<n;i++)P m,n-i,0,n+i+i-1,0);F=0;i<n-2;i++)P m,1,0,3*n-3,0);F=n-1;i;i--)P m,n-i,0,n+i+i-1,0);g(n);}


                                                            Try it online!



                                                            Ungolfed:



                                                            f(n){
                                                            int i;
                                                            printf("%*d",n,0);
                                                            for(i=0;i<n-1;i++){
                                                            printf("0");
                                                            }
                                                            printf("n");
                                                            for(i=1;i<n;i++){
                                                            printf("%*d%*dn",n-i,0,n+i+i-1,0);
                                                            }
                                                            for(i=0;i<n-2;i++){
                                                            printf("0%*dn",n+n+n-3,0);
                                                            }
                                                            for(i=n-1;i>0;i--){
                                                            printf("%*d%*dn",n-i,0,n+i+i-1,0);
                                                            }
                                                            printf("%*d",n,0);
                                                            for(i=0;i<n-1;i++){
                                                            printf("0");
                                                            }
                                                            }





                                                            share|improve this answer















                                                            C (clang), -DP=printf( -DF=for(i + 179 = 199 bytes





                                                            i;*m="%*d%*dn";g(n){P"%*d",n,0);F=0;i<n-1;i++)P"%d",0);P "n");}
                                                            f(n){g(n);F=1;i<n;i++)P m,n-i,0,n+i+i-1,0);F=0;i<n-2;i++)P m,1,0,3*n-3,0);F=n-1;i;i--)P m,n-i,0,n+i+i-1,0);g(n);}


                                                            Try it online!



                                                            Ungolfed:



                                                            f(n){
                                                            int i;
                                                            printf("%*d",n,0);
                                                            for(i=0;i<n-1;i++){
                                                            printf("0");
                                                            }
                                                            printf("n");
                                                            for(i=1;i<n;i++){
                                                            printf("%*d%*dn",n-i,0,n+i+i-1,0);
                                                            }
                                                            for(i=0;i<n-2;i++){
                                                            printf("0%*dn",n+n+n-3,0);
                                                            }
                                                            for(i=n-1;i>0;i--){
                                                            printf("%*d%*dn",n-i,0,n+i+i-1,0);
                                                            }
                                                            printf("%*d",n,0);
                                                            for(i=0;i<n-1;i++){
                                                            printf("0");
                                                            }
                                                            }






                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited 2 days ago

























                                                            answered Nov 7 at 3:32









                                                            Logern

                                                            68546




                                                            68546












                                                            • 180 bytes
                                                              – ceilingcat
                                                              Nov 8 at 12:08


















                                                            • 180 bytes
                                                              – ceilingcat
                                                              Nov 8 at 12:08
















                                                            180 bytes
                                                            – ceilingcat
                                                            Nov 8 at 12:08




                                                            180 bytes
                                                            – ceilingcat
                                                            Nov 8 at 12:08










                                                            up vote
                                                            1
                                                            down vote














                                                            Python 2, 130 bytes





                                                            def f(n):
                                                            a=[' '*~-n+n*'#']
                                                            b=[' '*(n-i-2)+'#'+' '*(n+2*i) +'#'for i in range(n-2)]
                                                            return a+b+['#%*s'%(3*n-3,'#')]*n+b[::-1]+a


                                                            Try it online!



                                                            On mobile, so not incredibly golfed.






                                                            share|improve this answer





















                                                            • You can remove the space after (n+2*i).
                                                              – Zacharý
                                                              Nov 8 at 13:26















                                                            up vote
                                                            1
                                                            down vote














                                                            Python 2, 130 bytes





                                                            def f(n):
                                                            a=[' '*~-n+n*'#']
                                                            b=[' '*(n-i-2)+'#'+' '*(n+2*i) +'#'for i in range(n-2)]
                                                            return a+b+['#%*s'%(3*n-3,'#')]*n+b[::-1]+a


                                                            Try it online!



                                                            On mobile, so not incredibly golfed.






                                                            share|improve this answer





















                                                            • You can remove the space after (n+2*i).
                                                              – Zacharý
                                                              Nov 8 at 13:26













                                                            up vote
                                                            1
                                                            down vote










                                                            up vote
                                                            1
                                                            down vote










                                                            Python 2, 130 bytes





                                                            def f(n):
                                                            a=[' '*~-n+n*'#']
                                                            b=[' '*(n-i-2)+'#'+' '*(n+2*i) +'#'for i in range(n-2)]
                                                            return a+b+['#%*s'%(3*n-3,'#')]*n+b[::-1]+a


                                                            Try it online!



                                                            On mobile, so not incredibly golfed.






                                                            share|improve this answer













                                                            Python 2, 130 bytes





                                                            def f(n):
                                                            a=[' '*~-n+n*'#']
                                                            b=[' '*(n-i-2)+'#'+' '*(n+2*i) +'#'for i in range(n-2)]
                                                            return a+b+['#%*s'%(3*n-3,'#')]*n+b[::-1]+a


                                                            Try it online!



                                                            On mobile, so not incredibly golfed.







                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Nov 6 at 19:02









                                                            TFeld

                                                            13.3k21039




                                                            13.3k21039












                                                            • You can remove the space after (n+2*i).
                                                              – Zacharý
                                                              Nov 8 at 13:26


















                                                            • You can remove the space after (n+2*i).
                                                              – Zacharý
                                                              Nov 8 at 13:26
















                                                            You can remove the space after (n+2*i).
                                                            – Zacharý
                                                            Nov 8 at 13:26




                                                            You can remove the space after (n+2*i).
                                                            – Zacharý
                                                            Nov 8 at 13:26










                                                            up vote
                                                            1
                                                            down vote













                                                            Batch, 260 bytes



                                                            @echo off
                                                            set s=
                                                            for /l %%i in (1,1,%1)do call set s= %%s%%
                                                            echo %s% %s: =#%
                                                            call:c %1,-1,3
                                                            for /l %%i in (1,1,%1)do echo #%s:~2%%s%%s:~2%#
                                                            call:c 3,1,%1
                                                            echo %s% %s: =#%
                                                            exit/b
                                                            :c
                                                            for /l %%i in (%*)do call echo %%s:~,%%i%%#%%s:~%%i%%%s%%%s:~%%i%%#


                                                            Outputs two leading spaces on each line. Explanation: Batch has no string repetition operator, limited string slicing capability and requires separate statements to perform arithmetic. It was therefore golfiest to make up a string of the input length in spaces (Batch can at least translate these to #s for the top and bottom lines) and then slice from or to a specific position ranging from 3 to the length to generate the diagonals (this is what the last line of the script achieves).






                                                            share|improve this answer

























                                                              up vote
                                                              1
                                                              down vote













                                                              Batch, 260 bytes



                                                              @echo off
                                                              set s=
                                                              for /l %%i in (1,1,%1)do call set s= %%s%%
                                                              echo %s% %s: =#%
                                                              call:c %1,-1,3
                                                              for /l %%i in (1,1,%1)do echo #%s:~2%%s%%s:~2%#
                                                              call:c 3,1,%1
                                                              echo %s% %s: =#%
                                                              exit/b
                                                              :c
                                                              for /l %%i in (%*)do call echo %%s:~,%%i%%#%%s:~%%i%%%s%%%s:~%%i%%#


                                                              Outputs two leading spaces on each line. Explanation: Batch has no string repetition operator, limited string slicing capability and requires separate statements to perform arithmetic. It was therefore golfiest to make up a string of the input length in spaces (Batch can at least translate these to #s for the top and bottom lines) and then slice from or to a specific position ranging from 3 to the length to generate the diagonals (this is what the last line of the script achieves).






                                                              share|improve this answer























                                                                up vote
                                                                1
                                                                down vote










                                                                up vote
                                                                1
                                                                down vote









                                                                Batch, 260 bytes



                                                                @echo off
                                                                set s=
                                                                for /l %%i in (1,1,%1)do call set s= %%s%%
                                                                echo %s% %s: =#%
                                                                call:c %1,-1,3
                                                                for /l %%i in (1,1,%1)do echo #%s:~2%%s%%s:~2%#
                                                                call:c 3,1,%1
                                                                echo %s% %s: =#%
                                                                exit/b
                                                                :c
                                                                for /l %%i in (%*)do call echo %%s:~,%%i%%#%%s:~%%i%%%s%%%s:~%%i%%#


                                                                Outputs two leading spaces on each line. Explanation: Batch has no string repetition operator, limited string slicing capability and requires separate statements to perform arithmetic. It was therefore golfiest to make up a string of the input length in spaces (Batch can at least translate these to #s for the top and bottom lines) and then slice from or to a specific position ranging from 3 to the length to generate the diagonals (this is what the last line of the script achieves).






                                                                share|improve this answer












                                                                Batch, 260 bytes



                                                                @echo off
                                                                set s=
                                                                for /l %%i in (1,1,%1)do call set s= %%s%%
                                                                echo %s% %s: =#%
                                                                call:c %1,-1,3
                                                                for /l %%i in (1,1,%1)do echo #%s:~2%%s%%s:~2%#
                                                                call:c 3,1,%1
                                                                echo %s% %s: =#%
                                                                exit/b
                                                                :c
                                                                for /l %%i in (%*)do call echo %%s:~,%%i%%#%%s:~%%i%%%s%%%s:~%%i%%#


                                                                Outputs two leading spaces on each line. Explanation: Batch has no string repetition operator, limited string slicing capability and requires separate statements to perform arithmetic. It was therefore golfiest to make up a string of the input length in spaces (Batch can at least translate these to #s for the top and bottom lines) and then slice from or to a specific position ranging from 3 to the length to generate the diagonals (this is what the last line of the script achieves).







                                                                share|improve this answer












                                                                share|improve this answer



                                                                share|improve this answer










                                                                answered Nov 7 at 9:20









                                                                Neil

                                                                77.6k744174




                                                                77.6k744174






















                                                                    up vote
                                                                    1
                                                                    down vote














                                                                    Ruby, 96 bytes





                                                                    ->n{[*(n-=2).step(z=n*3+2,2),*[z]*n,*z.step(n,-2)].map{|x|([?#]*2*('# '[x<=>n]*x)).center(z+2)}}


                                                                    Try it online!



                                                                    Not very golfed yet. Might golf if I find the time.






                                                                    share|improve this answer

























                                                                      up vote
                                                                      1
                                                                      down vote














                                                                      Ruby, 96 bytes





                                                                      ->n{[*(n-=2).step(z=n*3+2,2),*[z]*n,*z.step(n,-2)].map{|x|([?#]*2*('# '[x<=>n]*x)).center(z+2)}}


                                                                      Try it online!



                                                                      Not very golfed yet. Might golf if I find the time.






                                                                      share|improve this answer























                                                                        up vote
                                                                        1
                                                                        down vote










                                                                        up vote
                                                                        1
                                                                        down vote










                                                                        Ruby, 96 bytes





                                                                        ->n{[*(n-=2).step(z=n*3+2,2),*[z]*n,*z.step(n,-2)].map{|x|([?#]*2*('# '[x<=>n]*x)).center(z+2)}}


                                                                        Try it online!



                                                                        Not very golfed yet. Might golf if I find the time.






                                                                        share|improve this answer













                                                                        Ruby, 96 bytes





                                                                        ->n{[*(n-=2).step(z=n*3+2,2),*[z]*n,*z.step(n,-2)].map{|x|([?#]*2*('# '[x<=>n]*x)).center(z+2)}}


                                                                        Try it online!



                                                                        Not very golfed yet. Might golf if I find the time.







                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Nov 7 at 9:40









                                                                        G B

                                                                        7,4261327




                                                                        7,4261327






















                                                                            up vote
                                                                            1
                                                                            down vote














                                                                            Red, 171 bytes



                                                                            func[n][c:(a: n - 1)* 2 + n
                                                                            b: collect[loop c[keep pad/left copy"^/"c + 1]]s: 1x1 s/1: n
                                                                            foreach i[1x0 1 0x1 -1x1 -1x0 -1 0x-1 1x-1][loop a[b/(s/2)/(s/1): #"#"s: s + i]]b]


                                                                            Try it online!



                                                                            Explanation:



                                                                            Red
                                                                            f: func [ n ] [
                                                                            a: n - 1 ; size - 1
                                                                            c: a * 2 + n ; total size of widht / height
                                                                            b: collect [ ; create a block
                                                                            loop c [ ; composed of size - 1 rows
                                                                            keep pad/left copy "^/" c + 1 ; of empty lines of size c (and a newline)
                                                                            ]
                                                                            ]
                                                                            s: a * 1x0 + 1 ; starting coordinate
                                                                            foreach i [ 1x0 1 0x1 -1x1 -1x0 -1 0x-1 1x-1 ] [ ; for each offset for the 8 directions
                                                                            loop a [ ; repeat n - 1 times
                                                                            b/(s/2)/(s/1): #"#" ; set the array at current coordinate to "#"
                                                                            s: s + i ; next coordinate
                                                                            ]
                                                                            ]
                                                                            b ; return the block
                                                                            ]





                                                                            share|improve this answer



























                                                                              up vote
                                                                              1
                                                                              down vote














                                                                              Red, 171 bytes



                                                                              func[n][c:(a: n - 1)* 2 + n
                                                                              b: collect[loop c[keep pad/left copy"^/"c + 1]]s: 1x1 s/1: n
                                                                              foreach i[1x0 1 0x1 -1x1 -1x0 -1 0x-1 1x-1][loop a[b/(s/2)/(s/1): #"#"s: s + i]]b]


                                                                              Try it online!



                                                                              Explanation:



                                                                              Red
                                                                              f: func [ n ] [
                                                                              a: n - 1 ; size - 1
                                                                              c: a * 2 + n ; total size of widht / height
                                                                              b: collect [ ; create a block
                                                                              loop c [ ; composed of size - 1 rows
                                                                              keep pad/left copy "^/" c + 1 ; of empty lines of size c (and a newline)
                                                                              ]
                                                                              ]
                                                                              s: a * 1x0 + 1 ; starting coordinate
                                                                              foreach i [ 1x0 1 0x1 -1x1 -1x0 -1 0x-1 1x-1 ] [ ; for each offset for the 8 directions
                                                                              loop a [ ; repeat n - 1 times
                                                                              b/(s/2)/(s/1): #"#" ; set the array at current coordinate to "#"
                                                                              s: s + i ; next coordinate
                                                                              ]
                                                                              ]
                                                                              b ; return the block
                                                                              ]





                                                                              share|improve this answer

























                                                                                up vote
                                                                                1
                                                                                down vote










                                                                                up vote
                                                                                1
                                                                                down vote










                                                                                Red, 171 bytes



                                                                                func[n][c:(a: n - 1)* 2 + n
                                                                                b: collect[loop c[keep pad/left copy"^/"c + 1]]s: 1x1 s/1: n
                                                                                foreach i[1x0 1 0x1 -1x1 -1x0 -1 0x-1 1x-1][loop a[b/(s/2)/(s/1): #"#"s: s + i]]b]


                                                                                Try it online!



                                                                                Explanation:



                                                                                Red
                                                                                f: func [ n ] [
                                                                                a: n - 1 ; size - 1
                                                                                c: a * 2 + n ; total size of widht / height
                                                                                b: collect [ ; create a block
                                                                                loop c [ ; composed of size - 1 rows
                                                                                keep pad/left copy "^/" c + 1 ; of empty lines of size c (and a newline)
                                                                                ]
                                                                                ]
                                                                                s: a * 1x0 + 1 ; starting coordinate
                                                                                foreach i [ 1x0 1 0x1 -1x1 -1x0 -1 0x-1 1x-1 ] [ ; for each offset for the 8 directions
                                                                                loop a [ ; repeat n - 1 times
                                                                                b/(s/2)/(s/1): #"#" ; set the array at current coordinate to "#"
                                                                                s: s + i ; next coordinate
                                                                                ]
                                                                                ]
                                                                                b ; return the block
                                                                                ]





                                                                                share|improve this answer















                                                                                Red, 171 bytes



                                                                                func[n][c:(a: n - 1)* 2 + n
                                                                                b: collect[loop c[keep pad/left copy"^/"c + 1]]s: 1x1 s/1: n
                                                                                foreach i[1x0 1 0x1 -1x1 -1x0 -1 0x-1 1x-1][loop a[b/(s/2)/(s/1): #"#"s: s + i]]b]


                                                                                Try it online!



                                                                                Explanation:



                                                                                Red
                                                                                f: func [ n ] [
                                                                                a: n - 1 ; size - 1
                                                                                c: a * 2 + n ; total size of widht / height
                                                                                b: collect [ ; create a block
                                                                                loop c [ ; composed of size - 1 rows
                                                                                keep pad/left copy "^/" c + 1 ; of empty lines of size c (and a newline)
                                                                                ]
                                                                                ]
                                                                                s: a * 1x0 + 1 ; starting coordinate
                                                                                foreach i [ 1x0 1 0x1 -1x1 -1x0 -1 0x-1 1x-1 ] [ ; for each offset for the 8 directions
                                                                                loop a [ ; repeat n - 1 times
                                                                                b/(s/2)/(s/1): #"#" ; set the array at current coordinate to "#"
                                                                                s: s + i ; next coordinate
                                                                                ]
                                                                                ]
                                                                                b ; return the block
                                                                                ]






                                                                                share|improve this answer














                                                                                share|improve this answer



                                                                                share|improve this answer








                                                                                edited Nov 7 at 10:10

























                                                                                answered Nov 7 at 9:44









                                                                                Galen Ivanov

                                                                                5,68711032




                                                                                5,68711032






















                                                                                    up vote
                                                                                    1
                                                                                    down vote














                                                                                    APL (Dyalog Unicode), 46 bytesSBCS





                                                                                    (' '@~5 6∊⍨1⊥⊢∘,)⌺3 3⊢<(⍉⌽⌊⊢)⍣2∘(∘.+⍨∘⍳¯2+3×⊢)


                                                                                    This solution was provided by Adám - thanks!



                                                                                    Try it online!



                                                                                    My (almost) original solution:




                                                                                    APL (Dyalog Unicode), 61 bytesSBCS





                                                                                    (((⊃∘' #'¨1+5∘=+6∘=)⊢)1⊥⊢∘,)⌺3 3⊢<(((⊖⌊⊢)⌽⌊⊢)(∘.+⍨(⍳¯2+3×⊢)))


                                                                                    Try it online!



                                                                                    Thanks to Adám for his help!



                                                                                    The idea is to find the "diamond" that lies partly in the square and apply an edge-detect filter to "outline" the octagone.






                                                                                    share|improve this answer



















                                                                                    • 1




                                                                                      46: (' '@~5 6∊⍨1⊥⊢∘,)⌺3 3⊢<(⍉⌽⌊⊢)⍣2∘(∘.+⍨∘⍳¯2+3×⊢)
                                                                                      – Adám
                                                                                      Nov 7 at 13:51






                                                                                    • 1




                                                                                      You can't actually use Classic here because of . Rather count 1 byte/char by referring to SBCS as per Meta.
                                                                                      – Adám
                                                                                      Nov 7 at 13:52










                                                                                    • @Adám Thanks! I don't know how to edit the header, can you do it for me?
                                                                                      – Galen Ivanov
                                                                                      Nov 7 at 14:01










                                                                                    • What do you mean by editing the header?
                                                                                      – Adám
                                                                                      Nov 7 at 14:22






                                                                                    • 1




                                                                                      Edit and copy from here.
                                                                                      – Adám
                                                                                      Nov 7 at 14:40















                                                                                    up vote
                                                                                    1
                                                                                    down vote














                                                                                    APL (Dyalog Unicode), 46 bytesSBCS





                                                                                    (' '@~5 6∊⍨1⊥⊢∘,)⌺3 3⊢<(⍉⌽⌊⊢)⍣2∘(∘.+⍨∘⍳¯2+3×⊢)


                                                                                    This solution was provided by Adám - thanks!



                                                                                    Try it online!



                                                                                    My (almost) original solution:




                                                                                    APL (Dyalog Unicode), 61 bytesSBCS





                                                                                    (((⊃∘' #'¨1+5∘=+6∘=)⊢)1⊥⊢∘,)⌺3 3⊢<(((⊖⌊⊢)⌽⌊⊢)(∘.+⍨(⍳¯2+3×⊢)))


                                                                                    Try it online!



                                                                                    Thanks to Adám for his help!



                                                                                    The idea is to find the "diamond" that lies partly in the square and apply an edge-detect filter to "outline" the octagone.






                                                                                    share|improve this answer



















                                                                                    • 1




                                                                                      46: (' '@~5 6∊⍨1⊥⊢∘,)⌺3 3⊢<(⍉⌽⌊⊢)⍣2∘(∘.+⍨∘⍳¯2+3×⊢)
                                                                                      – Adám
                                                                                      Nov 7 at 13:51






                                                                                    • 1




                                                                                      You can't actually use Classic here because of . Rather count 1 byte/char by referring to SBCS as per Meta.
                                                                                      – Adám
                                                                                      Nov 7 at 13:52










                                                                                    • @Adám Thanks! I don't know how to edit the header, can you do it for me?
                                                                                      – Galen Ivanov
                                                                                      Nov 7 at 14:01










                                                                                    • What do you mean by editing the header?
                                                                                      – Adám
                                                                                      Nov 7 at 14:22






                                                                                    • 1




                                                                                      Edit and copy from here.
                                                                                      – Adám
                                                                                      Nov 7 at 14:40













                                                                                    up vote
                                                                                    1
                                                                                    down vote










                                                                                    up vote
                                                                                    1
                                                                                    down vote










                                                                                    APL (Dyalog Unicode), 46 bytesSBCS





                                                                                    (' '@~5 6∊⍨1⊥⊢∘,)⌺3 3⊢<(⍉⌽⌊⊢)⍣2∘(∘.+⍨∘⍳¯2+3×⊢)


                                                                                    This solution was provided by Adám - thanks!



                                                                                    Try it online!



                                                                                    My (almost) original solution:




                                                                                    APL (Dyalog Unicode), 61 bytesSBCS





                                                                                    (((⊃∘' #'¨1+5∘=+6∘=)⊢)1⊥⊢∘,)⌺3 3⊢<(((⊖⌊⊢)⌽⌊⊢)(∘.+⍨(⍳¯2+3×⊢)))


                                                                                    Try it online!



                                                                                    Thanks to Adám for his help!



                                                                                    The idea is to find the "diamond" that lies partly in the square and apply an edge-detect filter to "outline" the octagone.






                                                                                    share|improve this answer















                                                                                    APL (Dyalog Unicode), 46 bytesSBCS





                                                                                    (' '@~5 6∊⍨1⊥⊢∘,)⌺3 3⊢<(⍉⌽⌊⊢)⍣2∘(∘.+⍨∘⍳¯2+3×⊢)


                                                                                    This solution was provided by Adám - thanks!



                                                                                    Try it online!



                                                                                    My (almost) original solution:




                                                                                    APL (Dyalog Unicode), 61 bytesSBCS





                                                                                    (((⊃∘' #'¨1+5∘=+6∘=)⊢)1⊥⊢∘,)⌺3 3⊢<(((⊖⌊⊢)⌽⌊⊢)(∘.+⍨(⍳¯2+3×⊢)))


                                                                                    Try it online!



                                                                                    Thanks to Adám for his help!



                                                                                    The idea is to find the "diamond" that lies partly in the square and apply an edge-detect filter to "outline" the octagone.







                                                                                    share|improve this answer














                                                                                    share|improve this answer



                                                                                    share|improve this answer








                                                                                    edited Nov 7 at 15:08

























                                                                                    answered Nov 7 at 13:48









                                                                                    Galen Ivanov

                                                                                    5,68711032




                                                                                    5,68711032








                                                                                    • 1




                                                                                      46: (' '@~5 6∊⍨1⊥⊢∘,)⌺3 3⊢<(⍉⌽⌊⊢)⍣2∘(∘.+⍨∘⍳¯2+3×⊢)
                                                                                      – Adám
                                                                                      Nov 7 at 13:51






                                                                                    • 1




                                                                                      You can't actually use Classic here because of . Rather count 1 byte/char by referring to SBCS as per Meta.
                                                                                      – Adám
                                                                                      Nov 7 at 13:52










                                                                                    • @Adám Thanks! I don't know how to edit the header, can you do it for me?
                                                                                      – Galen Ivanov
                                                                                      Nov 7 at 14:01










                                                                                    • What do you mean by editing the header?
                                                                                      – Adám
                                                                                      Nov 7 at 14:22






                                                                                    • 1




                                                                                      Edit and copy from here.
                                                                                      – Adám
                                                                                      Nov 7 at 14:40














                                                                                    • 1




                                                                                      46: (' '@~5 6∊⍨1⊥⊢∘,)⌺3 3⊢<(⍉⌽⌊⊢)⍣2∘(∘.+⍨∘⍳¯2+3×⊢)
                                                                                      – Adám
                                                                                      Nov 7 at 13:51






                                                                                    • 1




                                                                                      You can't actually use Classic here because of . Rather count 1 byte/char by referring to SBCS as per Meta.
                                                                                      – Adám
                                                                                      Nov 7 at 13:52










                                                                                    • @Adám Thanks! I don't know how to edit the header, can you do it for me?
                                                                                      – Galen Ivanov
                                                                                      Nov 7 at 14:01










                                                                                    • What do you mean by editing the header?
                                                                                      – Adám
                                                                                      Nov 7 at 14:22






                                                                                    • 1




                                                                                      Edit and copy from here.
                                                                                      – Adám
                                                                                      Nov 7 at 14:40








                                                                                    1




                                                                                    1




                                                                                    46: (' '@~5 6∊⍨1⊥⊢∘,)⌺3 3⊢<(⍉⌽⌊⊢)⍣2∘(∘.+⍨∘⍳¯2+3×⊢)
                                                                                    – Adám
                                                                                    Nov 7 at 13:51




                                                                                    46: (' '@~5 6∊⍨1⊥⊢∘,)⌺3 3⊢<(⍉⌽⌊⊢)⍣2∘(∘.+⍨∘⍳¯2+3×⊢)
                                                                                    – Adám
                                                                                    Nov 7 at 13:51




                                                                                    1




                                                                                    1




                                                                                    You can't actually use Classic here because of . Rather count 1 byte/char by referring to SBCS as per Meta.
                                                                                    – Adám
                                                                                    Nov 7 at 13:52




                                                                                    You can't actually use Classic here because of . Rather count 1 byte/char by referring to SBCS as per Meta.
                                                                                    – Adám
                                                                                    Nov 7 at 13:52












                                                                                    @Adám Thanks! I don't know how to edit the header, can you do it for me?
                                                                                    – Galen Ivanov
                                                                                    Nov 7 at 14:01




                                                                                    @Adám Thanks! I don't know how to edit the header, can you do it for me?
                                                                                    – Galen Ivanov
                                                                                    Nov 7 at 14:01












                                                                                    What do you mean by editing the header?
                                                                                    – Adám
                                                                                    Nov 7 at 14:22




                                                                                    What do you mean by editing the header?
                                                                                    – Adám
                                                                                    Nov 7 at 14:22




                                                                                    1




                                                                                    1




                                                                                    Edit and copy from here.
                                                                                    – Adám
                                                                                    Nov 7 at 14:40




                                                                                    Edit and copy from here.
                                                                                    – Adám
                                                                                    Nov 7 at 14:40










                                                                                    up vote
                                                                                    1
                                                                                    down vote













                                                                                    Perl 5, 201 197 188 187 186 bytes:



                                                                                    $a=<>;$b=3*$a-4;$c='$"x($e-$_)."#".$"x$f."#n"';$e=($b-$a)/2+1;$d=$"x$e."#"x$a.$/;$f=$a;print$d,(map{(eval$c,$f+=2)[0]}1..$a-2),("#".$"x$b."#n")x$a,(map{$f-=2;eval$c}reverse 1..$a-2),$d


                                                                                    Try it online!



                                                                                    Reads the size of the octagon from first line of STDIN.






                                                                                    share|improve this answer










                                                                                    New contributor




                                                                                    Nathan Mills is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                    Check out our Code of Conduct.


















                                                                                    • Welcome to PPCG! You can probably shave off a few bytes here and there by using tricks found in this post.
                                                                                      – Mego
                                                                                      Nov 8 at 5:14










                                                                                    • @Mego Yep. I was able to save 4 bytes by using $" instead of " ".
                                                                                      – Nathan Mills
                                                                                      Nov 8 at 17:14















                                                                                    up vote
                                                                                    1
                                                                                    down vote













                                                                                    Perl 5, 201 197 188 187 186 bytes:



                                                                                    $a=<>;$b=3*$a-4;$c='$"x($e-$_)."#".$"x$f."#n"';$e=($b-$a)/2+1;$d=$"x$e."#"x$a.$/;$f=$a;print$d,(map{(eval$c,$f+=2)[0]}1..$a-2),("#".$"x$b."#n")x$a,(map{$f-=2;eval$c}reverse 1..$a-2),$d


                                                                                    Try it online!



                                                                                    Reads the size of the octagon from first line of STDIN.






                                                                                    share|improve this answer










                                                                                    New contributor




                                                                                    Nathan Mills is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                    Check out our Code of Conduct.


















                                                                                    • Welcome to PPCG! You can probably shave off a few bytes here and there by using tricks found in this post.
                                                                                      – Mego
                                                                                      Nov 8 at 5:14










                                                                                    • @Mego Yep. I was able to save 4 bytes by using $" instead of " ".
                                                                                      – Nathan Mills
                                                                                      Nov 8 at 17:14













                                                                                    up vote
                                                                                    1
                                                                                    down vote










                                                                                    up vote
                                                                                    1
                                                                                    down vote









                                                                                    Perl 5, 201 197 188 187 186 bytes:



                                                                                    $a=<>;$b=3*$a-4;$c='$"x($e-$_)."#".$"x$f."#n"';$e=($b-$a)/2+1;$d=$"x$e."#"x$a.$/;$f=$a;print$d,(map{(eval$c,$f+=2)[0]}1..$a-2),("#".$"x$b."#n")x$a,(map{$f-=2;eval$c}reverse 1..$a-2),$d


                                                                                    Try it online!



                                                                                    Reads the size of the octagon from first line of STDIN.






                                                                                    share|improve this answer










                                                                                    New contributor




                                                                                    Nathan Mills is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                    Check out our Code of Conduct.









                                                                                    Perl 5, 201 197 188 187 186 bytes:



                                                                                    $a=<>;$b=3*$a-4;$c='$"x($e-$_)."#".$"x$f."#n"';$e=($b-$a)/2+1;$d=$"x$e."#"x$a.$/;$f=$a;print$d,(map{(eval$c,$f+=2)[0]}1..$a-2),("#".$"x$b."#n")x$a,(map{$f-=2;eval$c}reverse 1..$a-2),$d


                                                                                    Try it online!



                                                                                    Reads the size of the octagon from first line of STDIN.







                                                                                    share|improve this answer










                                                                                    New contributor




                                                                                    Nathan Mills is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                    Check out our Code of Conduct.









                                                                                    share|improve this answer



                                                                                    share|improve this answer








                                                                                    edited Nov 8 at 17:30





















                                                                                    New contributor




                                                                                    Nathan Mills is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                    Check out our Code of Conduct.









                                                                                    answered Nov 8 at 4:31









                                                                                    Nathan Mills

                                                                                    112




                                                                                    112




                                                                                    New contributor




                                                                                    Nathan Mills is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                    Check out our Code of Conduct.





                                                                                    New contributor





                                                                                    Nathan Mills is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                    Check out our Code of Conduct.






                                                                                    Nathan Mills is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                    Check out our Code of Conduct.












                                                                                    • Welcome to PPCG! You can probably shave off a few bytes here and there by using tricks found in this post.
                                                                                      – Mego
                                                                                      Nov 8 at 5:14










                                                                                    • @Mego Yep. I was able to save 4 bytes by using $" instead of " ".
                                                                                      – Nathan Mills
                                                                                      Nov 8 at 17:14


















                                                                                    • Welcome to PPCG! You can probably shave off a few bytes here and there by using tricks found in this post.
                                                                                      – Mego
                                                                                      Nov 8 at 5:14










                                                                                    • @Mego Yep. I was able to save 4 bytes by using $" instead of " ".
                                                                                      – Nathan Mills
                                                                                      Nov 8 at 17:14
















                                                                                    Welcome to PPCG! You can probably shave off a few bytes here and there by using tricks found in this post.
                                                                                    – Mego
                                                                                    Nov 8 at 5:14




                                                                                    Welcome to PPCG! You can probably shave off a few bytes here and there by using tricks found in this post.
                                                                                    – Mego
                                                                                    Nov 8 at 5:14












                                                                                    @Mego Yep. I was able to save 4 bytes by using $" instead of " ".
                                                                                    – Nathan Mills
                                                                                    Nov 8 at 17:14




                                                                                    @Mego Yep. I was able to save 4 bytes by using $" instead of " ".
                                                                                    – Nathan Mills
                                                                                    Nov 8 at 17:14










                                                                                    up vote
                                                                                    0
                                                                                    down vote














                                                                                    C (gcc), 158 153 bytes




                                                                                    • Saved five bytes thanks to ceilingcat.


                                                                                    O,c,t,g;o(n){for(O=2*~-n,t=c=O+n;t--;puts(""))for(g=c;g--;)putchar(32+(!t|t>c-2?g>n-2&g<=O:t<n-1|t>O?t+O==g|t-O==g|c-g-t-n==n-1|c-g-t+n==3-n:!g|g>c-2));}


                                                                                    Try it online!






                                                                                    share|improve this answer























                                                                                    • @ceilingcat Thank you.
                                                                                      – Jonathan Frech
                                                                                      Nov 8 at 21:00















                                                                                    up vote
                                                                                    0
                                                                                    down vote














                                                                                    C (gcc), 158 153 bytes




                                                                                    • Saved five bytes thanks to ceilingcat.


                                                                                    O,c,t,g;o(n){for(O=2*~-n,t=c=O+n;t--;puts(""))for(g=c;g--;)putchar(32+(!t|t>c-2?g>n-2&g<=O:t<n-1|t>O?t+O==g|t-O==g|c-g-t-n==n-1|c-g-t+n==3-n:!g|g>c-2));}


                                                                                    Try it online!






                                                                                    share|improve this answer























                                                                                    • @ceilingcat Thank you.
                                                                                      – Jonathan Frech
                                                                                      Nov 8 at 21:00













                                                                                    up vote
                                                                                    0
                                                                                    down vote










                                                                                    up vote
                                                                                    0
                                                                                    down vote










                                                                                    C (gcc), 158 153 bytes




                                                                                    • Saved five bytes thanks to ceilingcat.


                                                                                    O,c,t,g;o(n){for(O=2*~-n,t=c=O+n;t--;puts(""))for(g=c;g--;)putchar(32+(!t|t>c-2?g>n-2&g<=O:t<n-1|t>O?t+O==g|t-O==g|c-g-t-n==n-1|c-g-t+n==3-n:!g|g>c-2));}


                                                                                    Try it online!






                                                                                    share|improve this answer















                                                                                    C (gcc), 158 153 bytes




                                                                                    • Saved five bytes thanks to ceilingcat.


                                                                                    O,c,t,g;o(n){for(O=2*~-n,t=c=O+n;t--;puts(""))for(g=c;g--;)putchar(32+(!t|t>c-2?g>n-2&g<=O:t<n-1|t>O?t+O==g|t-O==g|c-g-t-n==n-1|c-g-t+n==3-n:!g|g>c-2));}


                                                                                    Try it online!







                                                                                    share|improve this answer














                                                                                    share|improve this answer



                                                                                    share|improve this answer








                                                                                    edited Nov 8 at 21:00

























                                                                                    answered Nov 8 at 13:34









                                                                                    Jonathan Frech

                                                                                    6,16311040




                                                                                    6,16311040












                                                                                    • @ceilingcat Thank you.
                                                                                      – Jonathan Frech
                                                                                      Nov 8 at 21:00


















                                                                                    • @ceilingcat Thank you.
                                                                                      – Jonathan Frech
                                                                                      Nov 8 at 21:00
















                                                                                    @ceilingcat Thank you.
                                                                                    – Jonathan Frech
                                                                                    Nov 8 at 21:00




                                                                                    @ceilingcat Thank you.
                                                                                    – Jonathan Frech
                                                                                    Nov 8 at 21:00










                                                                                    up vote
                                                                                    0
                                                                                    down vote














                                                                                    Python 3, 224 bytes





                                                                                    n=int(input())
                                                                                    z=" "*(n-1)+"#"*n+" "*(n-1)
                                                                                    print(z)
                                                                                    for i in range(n-2):print(" "*(n-i-2)+"#"+" "*(i*2+n)+"#")
                                                                                    print((("#"+" "*(n*3-4)+"#n")*n)[:-1])
                                                                                    for i in range(n-3,-1,-1):print(" "*(n-i-2)+"#"+" "*(i*2+n)+"#")
                                                                                    print(z)


                                                                                    Try it online!






                                                                                    share|improve this answer








                                                                                    New contributor




                                                                                    glietz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                    Check out our Code of Conduct.






















                                                                                      up vote
                                                                                      0
                                                                                      down vote














                                                                                      Python 3, 224 bytes





                                                                                      n=int(input())
                                                                                      z=" "*(n-1)+"#"*n+" "*(n-1)
                                                                                      print(z)
                                                                                      for i in range(n-2):print(" "*(n-i-2)+"#"+" "*(i*2+n)+"#")
                                                                                      print((("#"+" "*(n*3-4)+"#n")*n)[:-1])
                                                                                      for i in range(n-3,-1,-1):print(" "*(n-i-2)+"#"+" "*(i*2+n)+"#")
                                                                                      print(z)


                                                                                      Try it online!






                                                                                      share|improve this answer








                                                                                      New contributor




                                                                                      glietz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                      Check out our Code of Conduct.




















                                                                                        up vote
                                                                                        0
                                                                                        down vote










                                                                                        up vote
                                                                                        0
                                                                                        down vote










                                                                                        Python 3, 224 bytes





                                                                                        n=int(input())
                                                                                        z=" "*(n-1)+"#"*n+" "*(n-1)
                                                                                        print(z)
                                                                                        for i in range(n-2):print(" "*(n-i-2)+"#"+" "*(i*2+n)+"#")
                                                                                        print((("#"+" "*(n*3-4)+"#n")*n)[:-1])
                                                                                        for i in range(n-3,-1,-1):print(" "*(n-i-2)+"#"+" "*(i*2+n)+"#")
                                                                                        print(z)


                                                                                        Try it online!






                                                                                        share|improve this answer








                                                                                        New contributor




                                                                                        glietz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                        Check out our Code of Conduct.










                                                                                        Python 3, 224 bytes





                                                                                        n=int(input())
                                                                                        z=" "*(n-1)+"#"*n+" "*(n-1)
                                                                                        print(z)
                                                                                        for i in range(n-2):print(" "*(n-i-2)+"#"+" "*(i*2+n)+"#")
                                                                                        print((("#"+" "*(n*3-4)+"#n")*n)[:-1])
                                                                                        for i in range(n-3,-1,-1):print(" "*(n-i-2)+"#"+" "*(i*2+n)+"#")
                                                                                        print(z)


                                                                                        Try it online!







                                                                                        share|improve this answer








                                                                                        New contributor




                                                                                        glietz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                        Check out our Code of Conduct.









                                                                                        share|improve this answer



                                                                                        share|improve this answer






                                                                                        New contributor




                                                                                        glietz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                        Check out our Code of Conduct.









                                                                                        answered 2 days ago









                                                                                        glietz

                                                                                        416




                                                                                        416




                                                                                        New contributor




                                                                                        glietz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                        Check out our Code of Conduct.





                                                                                        New contributor





                                                                                        glietz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                        Check out our Code of Conduct.






                                                                                        glietz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                        Check out our Code of Conduct.






























                                                                                             

                                                                                            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




















































































                                                                                            Popular posts from this blog

                                                                                            鏡平學校

                                                                                            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                                                                                            Why https connections are so slow when debugging (stepping over) in Java?