# Could you make me a hexagon please?

Today, we're going to make an ASCII hexagon. You must write a program or function that takes a positive integer n, and outputs a hexagon grid of size n, made up of asterisks. For example, a hexagon of size 2 looks like this:

 * *
* * *
* *


While a hexagon of size 3 looks like this:

  * * *
* * * *
* * * * *
* * * *
* * *


You may use any of the default input and output methods, for example STDIO/STDOUT, function arguments and return values or reading/writing a file.

You may assume that input is always valid, so if it's not a positive integer, your program may do whatever you want. You do however have to handle the special case of a size 1 hexagon, which happens to be a single asterisk:

*


Leading and trailing whitespace is allowed as long as the output is visually the same.

# Examples:

1:
*

2:
* *
* * *
* *

3:
* * *
* * * *
* * * * *
* * * *
* * *

4:
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *

5:
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *

6:
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *

12:
* * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * *


As usual, this is , so standard loopholes apply, and you should try to write the shortest possible program measured in bytes. Of course, some languages are inherently shorter or longer than others, so remember that the goal is not necessarily to have the shortest overall byte count, but to beat submissions in the same or similar languages.

May the best golfer win!

• Why do we even have a hexagonal-grid tag? Dec 26 '16 at 7:25
• Also, someone needs to write a hexagony solution. Dec 26 '16 at 7:40
• If anyone wants to go for the bounty, you can probably reuse the output loop of my Hexagony answer over here. Jan 19 '17 at 9:01
• "Could you make me a hexagon please?" - sure, here you go: i.imgur.com/1emYIia.png Jan 28 '17 at 18:45
• @Pavel because a lot of operations on a hexagonal grid are distinct from on the more standard square grid, and portable between solutions to different problems. Such operations as coordinate manipulation, rotation, output layout, etc. Jun 28 '18 at 5:25

# Excel, 63 bytes

=LET(r,2*A1-1,x,ABS(A1-SEQUENCE(r)),REPT(" ",x)&REPT("* ",r-x))


The above spills the results to multiple cells. The 75 byte formula for a single cells answer is below.

=LET(r,2*A1-1,x,ABS(A1-SEQUENCE(r)),CONCAT(REPT(" ",x)&REPT("* ",r-x)&"
"))


# C (gcc), 164125124 123 bytes

i,h;main(z,b)int**b;{z=atoi(b[1]);for(i=z--+z;i--;puts(""))for(h=z<i?z-i+z:i,printf("%*s",z-h,""),h-=~z;h--;)printf("* ");}


Try it online!

• i completely didn't see arguments at all lol, also i forgot about puts lol
– mekb
Jul 14 '21 at 12:31