[Question]
  [
Again inspired by a task for Programming 101 here's another challenge.
**Input:**
* A positive integer `n >= 3`. (has to be odd)
**Output:**
* `n` lines of asterisks, where the first line has `n` asterisks and every new line has two asterisks less than the line before. Until hitting 1 asterisk. From there every new line has two asterisks more than the line before until getting back to `n` asterisks. Spaces or something like spaces have to used to align the asterisks so that it really will look like an hourglass.
**General rules:**
* Trailing newlines are allowed but do not have to be used.
* indentation is a must.
* This is code-golf, so shortest answer in bytes wins.
* Since the course is taught in C++, I'm eager to see solutions in C++.
**Test case (n=5):**
```
*****
 ***
  *
 ***
*****
```
  
[Answer]
## [Charcoal](http://github.com/somebody1234/Charcoal), 6 bytes
```
Ｇ↘←↗Ｎ*
```
Dead simple. Draw a poly**G**on of `*`, with side length taken from an input **N**umber, where the sides go down-and-right, horizontally left, and up-and-right:
```
*   *
 * *
  *
 * *
*****
```
Then autocomplete the outline and fill it.
```
*****
 ***
  *
 ***
*****
```
[Try it online!](http://charcoal.tryitonline.net/#code=77yn4oaY4oaQ4oaX77yuKg&input=NQ)
[Answer]
## Python 2, 57 bytes
```
N=n=input()
exec"print('*'*max(n,2-n)).center(N);n-=2;"*n
```
A full program. Goes line by line, printing the right number of asterisks centered.
A recursive function was longer (67 bytes):
```
f=lambda n,p='':p+n*'*'+'\n'+(1%n*' 'and f(n-2,p+' ')+p+n*'*'+'\n')
```
or 
```
f=lambda n,p='':1/n*(p+'*\n')or f(n-2,p+' ').join([p+n*'*'+'\n']*2)
```
[Answer]
# [V](http://github.com/DJMcMayhem/V), 12 bytes
```
Àé*hòl3Äjxx>
```
[Try it online!](http://v.tryitonline.net/#code=w4DDqSpow7JsM8OEanh4Pg&input=&args=NQ)
I like challenges like this because I get to show off the advantages of V's 2D nature. Explanation. First, we need to create a string of *n* asterisks. So, we do this:
```
À           " Arg1 times:
 é          " Insert the following single character:
  *         " '*'
```
As a side note, this is directly equivalent to `@ai*<esc>` in vim, and register `@a` is pre-initialized to "arg1". This makes numeric input much more convenient.
Then, we move on character to the right with `h`. Here is the fun part:
```
ò           " Until an error is thrown:
 l          "   Move one character to the right. This will throw an error on anyline with only one asterisk in it
  3Ä        "   Make 3 copies of this line
    j       "   Move down one line
     xx     "   Delete two characters
       >    "   Indent this line once.
```
Now technically, this last part is
```
òl3Äjxx>>ò
```
Because the indent command is actually `>>`. V conveniently assumes incomplete commands apply to the current line, and also implicitly fills in the second `ò` character for looping.
[Answer]
# C++ Metatemplates, 186 bytes
With the explicit formula from [my C answer](https://codegolf.stackexchange.com/a/97401/53667) the Metatemplates are competing!
```
template<int N,int X=N*N+N-1>struct H{enum{I=X/(N+1)-N/2,J=X%(N+1)-N/2-1};S s{(J==-N/2-1?'\n':((I>=J&I>=-J)|(I<=J&I<=-J)?'*':' '))+H<N,X-1>().s};};template<int N>struct H<N,-1>{S s="";};
```
Ungolfed:
```
using S=std::string;
template <int N, int X=N*N+N-1>
struct H{
 enum{I=X/(N+1)-N/2,J=X%(N+1)-N/2-1};
 S s{(J==-N/2-1 ? '\n' : ( (I>=J&I>=-J)|(I<=J&I<=-J) ?'*':' '))+H<N,X-1>().s};
};
template <int N> struct H<N,-1> {S s="";}; 
```
usage:
```
std::cout << H<5>().s;
```
### non-competing
Just for the sake of fun:
```
//T: Tuple of chars
template <char C, char...Tail> struct T { S r=S(1,C)+T<Tail...>().r; };
//specialization for single char
template <char C> struct T<C> { S r=S(1,C); };
//M: Repeated char
template <int N, char C> struct M { S r=S(N,C); };
//U: concatenates T and M
template <class Head, class...Tail> struct U { S r=Head().r+U<Tail...>().r; };
//specialization for Tail=M
template <int N, char C> struct U<M<N,C>> { S r{M<N,C>().r}; };
//specialization for Tail=T
template <char...C> struct U<T<C...>> { S r=T<C...>().r; };
//finally the Hourglass
template <int N, int I=0> struct H {
 S s=U<
       M<I,' '>,
       M<N,'*'>,
       T<'\n'>
      >().r;
 S r{s + H<N-2,I+1>().r + s};
};
//specialization for recursion end
template <int I> struct H<1,I> {
 S r=U<
       M<I,' '>,
       T<'*','\n'>
      >().r;
};
```
Usage:
```
std::cout << H<5>().r;
```
[Answer]
## PowerShell v2+, 54 bytes
```
param($n)$n..1+2..$n|?{$_%2}|%{" "*(($n-$_)/2)+"*"*$_}
```
Takes input `$n` (guaranteed to be an odd integer), constructs two ranges with `$n..1` and `2..$n` and concatenates them together, then uses `Where-Object` to select only the odd ones with `|?{$_%2}`. Those are fed into a loop. Each iteration, we construct the appropriate number of spaces, string-concatenated with the appropriate number of asterisks. Those strings are left on the pipeline, and output via implicit `Write-Output` inserts newlines between them at program completion.
### Examples
```
PS C:\Tools\Scripts\golfing> 3,5,7|%{.\draw-an-hourglass.ps1 $_;""}
***
 *
***
*****
 ***
  *
 ***
*****
*******
 *****
  ***
   *
  ***
 *****
*******
```
[Answer]
# Python, 78 bytes
So only with indentation:
```
f=lambda n,i=0:n>1and' '*i+'*'*n+'\n'+f(n-2,i+1)+' '*i+'*'*n+'\n'or' '*i+'*\n'
```
Usage:
```
print f(5)
```
[Answer]
# C, ~~114~~ 109 bytes
```
i,j;k(n){for(i=-n/2;i<=n/2;++i)for(j=-n/2;j<=n/2+1;++j)putchar(j==n/2+1?10:(i>=j&i>=-j)|(i<=j&i<=-j)?42:32);}
```
ungolfed:
```
i,j;
k(n){
 for(i=-n/2;i<=n/2;++i)
  for(j=-n/2;j<=n/2+1;++j)
   putchar(j==n/2+1?10:(i>=j&i>=-j)|(i<=j&i<=-j)?42:32);
}
```
Previous recursive solution:
```
p(a,c){while(a--)putchar(c);}
f(n,i){p(i,32);p(n,42);p(1,10);}
g(n,i){if(n>1)f(n,i),g(n-2,i+1);f(n,i);}
h(n){g(n,0);}
```
[Answer]
# JavaScript (ES6), 66 bytes
```
f=(n,s="*".repeat(n))=>n>1?s+`
`+f(n-2).replace(/^/gm," ")+`
`+s:s
```
The idea here is to generate each hourglass from the previous: add a space at the beginning of every line, and both prepend and append `n` asterisks.
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), ~~21~~ ~~20~~ ~~19~~ 17 bytes
Saved 2 bytes thanks to *carusocomputing*
```
;ƒ'*¹N·-×Nð×ì})û»
```
[Try it online!](http://05ab1e.tryitonline.net/#code=O8aSJyrCuU7Cty3Dl07DsMOXw6x9KcO7wrs&input=OQ)
**Explanation**
```
;ƒ                   # for N in [0 ... floor(input/2)+1]
  '*                 # push an asterisk
    ¹N·-×            # repeat the asterisk input-N*2 times
         Nð×ì        # prepend N spaces
             }       # end loop
              )      # wrap stack in a list
               û     # palendromize
                »    # join with newlines
```
[Answer]
# [MATL](http://github.com/lmendo/MATL), 12 bytes
```
Q2/Zv&<~42*c
```
[Try it online!](http://matl.tryitonline.net/#code=UTIvWnYmPH40Mipj&input=NQ)
### Explanation
This makes use of the [recently added](https://github.com/lmendo/MATL/releases/tag/19.3.0) *symmetric range* function.
```
Q     % Input n implicitly. Add 1
      % STACK: 6
2/    % Divide by 2
      % STACK: 3
Zv    % Symmetric range
      % STACK: [1 2 3 2 1]
&<~   % Matrix of all pairwise "greater than or or equal to" comparisons
      % STACK: [1 1 1 1 1
                0 1 1 1 0
                0 0 1 0 0
                0 1 1 1 0
                1 1 1 1 1]
42*   % Multiply by 42 (ASCII code of '*')
      % STACK: [42 42 42 42 42
                 0 42 42 42  0
                 0  0 42  0  0
                 0 42 42 42  0
                42 42 42 42 42]
c     % Convert to char. Implicitly display, with char 0 shown as space
      % STACK: ['*****'
                ' *** '
                '  *  '
                ' *** '
                '*****']
```
[Answer]
# PHP, 95 bytes
```
for($c=str_pad,$m=$n=$argv[1];$n<=$m;$n+=$d=$d>0||$n<2?2:-2)echo$c($c('',$n,'*'),$m,' ',2)."
";
```
Instead of storing the rows in an array and then outputting everything, the for loop goes down until 1, and then goes back up to the original number.
[Answer]
# C++11, 93 bytes
```
#include<string>
using S=std::string;S f(int n,int i=0){S s=S(i,32)+S(n,42)+'\n';return n>1?s+f(n-2,i+1)+s:s;}
```
Slightly ungolfed:
```
std::string f(int n,int i=0){
 auto s=std::string(i,' ') + std::string(n,'*') + '\n';
 return n>1 ? s+f(n-2,i+1)+s : s;
}
```
Usage:
```
std::cout << f(5);
```
[Answer]
# [MATL](http://github.com/lmendo/MATL), 20 bytes
```
XyY>t1X!*t2X!+ZS42*c
```
[Try it online!](http://matl.tryitonline.net/#code=WHlZPnQxWCEqdDJYIStaUzQyKmM&input=NQ)
[Answer]
# C, 79 bytes
```
h(m,n,k){for(n=m++,k=n*m;--k;putchar(k%m?abs(k%m-m/2)>abs(k/m-n/2)?32:42:10));}
```
It splits the countdown variable `k` into row and column indices.
If the column index is 0 (last char in a row), it outputs a newline character (10). Then it adjusts the row and column indices to be around the center asterisk. Then, `abs(x) < abs(y)` is a short condition for outputting a space.
[Answer]
# R, 77 bytes
```
M=matrix(" ",n<-scan(),n);for(i in 1:n)M[i:(n-i+1),i]="*";cat(M,sep="",fill=n)
```
Creates a character matrix, which it then prints out via `cat`, with `fill=n` making sure the lines align properly. Note that elements are stored in a matrix column-first (i.e the first two elements are `M[1,1]` and `M[2,1]`, not `M[1,2]`.)
[Answer]
# Java 7, ~~170 165~~ 164 bytes
*Thanks to @Hypino for saving 5 bytes.*  
*Thanks to Kevin for saving 1 byte.*
```
String c(int n,int x){String s,c,t=c=s=" ";int i=0;for(;i++<n;s+="*");for(i=x;i-->=0;c+=" ");for(i=x;i-->0;t+=" ");return(n=n-2)>=0?s+"\n"+c+c(n,++x)+"\n"+t+s:"*";} 
```
[Answer]
## PHP - 95 bytes
```
$c=2;for($i=$a=$argv[1];$i<=$a;$i-=$c*=$i<2?-1:1)echo str_pad(str_repeat("*",$i),$a," ",2)."
";
```
Saved a byte by using an actual new line instead of an `"\r"`
[Answer]
# APL, 19 bytes
```
' *'[1+∘.≤⍨(⊢⌊⌽)⍳⎕]
```
Test:
```
      ' *'[1+∘.≤⍨(⊢⌊⌽)⍳⎕]
⎕:
      5
*****
 *** 
  *  
 *** 
*****
```
Explanation:
```
                 ⎕   ⍝ read number  
                ⍳    ⍝ 1..N
           ( ⌊ )     ⍝ at each position, minimum of
            ⊢        ⍝ 1..N
              ⌽      ⍝ and N..1 (this gives 1..N/2..1)
       ∘.≤⍨          ⍝ outer product with ≤
     1+              ⍝ add 1 to each value
' *'[             ]  ⍝ 1→space, 2→asterisk
```
[Answer]
# [Canvas](https://github.com/dzaima/Canvas), 7 [bytes](https://github.com/dzaima/Canvas/blob/master/files/chartable.md)
```
⇵｛*×］⤢┼
```
[Try it here!](https://dzaima.github.io/Canvas/?u=JXUyMUY1JXVGRjVCKiVENyV1RkYzRCV1MjkyMiV1MjUzQw__,i=NQ__,v=0)
Explanation:
```
⇵｛*×］⤢┼
⇵         ceiling divide by 2
 ｛  ］    map over [1..pop]
   *         push *
    ×        repeat by the counter
       ⤢  transpose
        ┼  quad-palindromize with 1 overlap
```
[+1 byte](https://dzaima.github.io/Canvas/?u=JXUyMUY1JXVGRjVCKiVENyV1RkYzRCV1MjkyMiV1MjUzQyV1MjU2Qw__,i=Ng__,v=0) with support for even numbers
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~54~~ 50 bytes
```
filter f{if($_-1){'*'*$_;($_-2)|f|%{" $_"}}'*'*$_}
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/Py0zpyS1SCGtOjNNQyVe11CzWl1LXUsl3hrEM9KsSatRrVZSUIlXqq2FSNT@N9Yx1TEHCnMpAIFKfE0amKGuzlX7HwA "PowerShell – Try It Online")
[Answer]
# [PHP](https://php.net/), ~~104~~ 88 bytes
```
for(;$i++<$argn;$a.='**',$i++>1?$o=$s.$o:1)$o.=$s=str_pad("*$a",$argn,' ',2)."
";echo$o;
```
[Try it online!](https://tio.run/##K8go@G9jX5BRoKCSWJSeZ5uWnlpSrBEc4uLpp2n9Py2/SMNaJVNb2wYsa62SqGerrqWlrgMSszO0V8m3VSnWU8m3MtRUydcDsm2LS4riCxJTNJS0VBKVdMC6dNQV1HWMNPWUuJSsU5Mz8lXyrf//NwcA "PHP – Try It Online")
~~This doesn't beat the lowest scores for PHP on this challenge, but it's just too crazy for me to throw away.~~
Okay, so I've golfed now it to be the (not for long) lowest score for PHP on this challenge, but it doesn't change the fact that it's still crazy. 
```
$ echo 7|php -nF hour.php
*******
 *****
  ***
   *
  ***
 *****
*******
```
[Answer]
# [Add++](https://github.com/cairdcoinheringaahing/AddPlusPlus), 90 bytes
```
+?
Fx,`i,j:i,-1,*" ",o,`j,x-,+1,+j,-1,*"a",O
x-1
Fx,`i,+1,j:i,x-,+1,*" ",o,`j,*2,-1,*"a",O
```
[Try it online!](https://tio.run/##S0xJKSj4/1/bnsutQichUyfLKlNH11BHS0lBSSdfJyFLp0JXR9tQRzsLIpqopOPPVaFrCFUNlAFpgKhB6NEyQqj@//@/KQA "Add++ – Try It Online")
Just two for loops.
My first Add++ answer!
[Answer]
# [J](http://jsoftware.com/), ~~30~~ ~~28~~ ~~26~~ 25 bytes
-2 bytes thanks to FrownyFrog!
-3 bytes thanks to Jonah!
```
' *'#~](],.(-+:))i.@-<.i.
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/1RW01JXrYjVidfQ0dLWtNDUz9Rx0bfQy9f5rcilwpSZn5CukKZhCGOrqMAFDw/8A "J – Try It Online")
## Previous version:
```
' *'{~[:(>.|.)@(*|."1)]\@#&1
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/1RW01Kvroq007PRq9DQdNLRq9JQMNWNjHJTVDP9rcilwpSZn5CukKZhCGOrqMAFDw/8A "J – Try It Online")
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal) `C`, ~~14~~ ~~13~~ 11 bytes
-2 thanks to @Lyxal
```
½ʀƛd⁰ε×*;øm
```
Port of [Emigna's 05AB1E solution](https://codegolf.stackexchange.com/a/97414/80050).
[Try it Online!](http://lyxal.pythonanywhere.com?flags=C&code=%C2%BD%CA%80%C6%9Bd%E2%81%B0%CE%B5%C3%97*%3B%C3%B8m&inputs=7&header=&footer=)
```
½ʀƛd⁰ε×*;øm    # Full program
  ƛ     ;      # Map each n
½ʀ             # in range(0, input / 2 + 1):
       *        # Repeat...
      ×         # the character `*`...
   d⁰ε          # abs(2 * n - input) times
          øm   # Palindromize
               # Implicit output (`C' flag): join the array on newlines and center each line
```
[Answer]
# Pyth, 22 bytes
```
j+J.e+*dk*b\*_:1hQ2_PJ
```
A program that takes input of an integer on STDIN and prints the result.
[Try it online](https://pyth.herokuapp.com/?code=j%2BJ.e%2B%2adk%2ab%5C%2a_%3A1hQ2_PJ&input=9&debug=0)
**How it works**
```
j+J.e+*dk*b\*_:1hQ2_PJ  Program. Input: Q
              :1hQ2     Range from 1 to Q+1 in steps of 2. Yields [1, 3, 5, ..., Q]
             _          Reverse
   .e                   Enumnerated map with b as elements and k as indices:
      *dk                 k spaces
         *b\*             b asterisks
     +                    Concatenate the spaces and asterisks
  J                     Store in J
                    PJ  All of J except the last element
                   _    Reverse
 +                      Concatenate J and its modified reverse
j                       Join on newlines
                        Implicitly print
```
[Answer]
# C, ~~195~~ 191 Bytes
Should golf down a bit smaller
```
x,y,i;f(n){for(i=0;i<n;i+=2,puts("")){for(y=n-i;y<n;y+=2,putchar(32));for(x=i;x++<n;putchar(42));}for(i=n-2;~i;i-=2,puts("")){for(y=n-i+2;y<n;y+=2,putchar(32));for(x=i-1;x++<n;putchar(42));}}
```
We can test it [here](http://ideone.com/cV2Oh1) on ideone
[Answer]
# Ruby, ~~55~~ 54 bytes
```
f=->n,s=0{puts a=' '*s+?**n;(f[n-2,s+1];puts a)if n>1}
```
[Answer]
# Haskell, 84 bytes
```
f n|l<-div n 2,k<-[-l..l]=putStr$unlines[[" *"!!(fromEnum$abs x<=abs y)|x<-k]|y<-k]
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~80~~ 74 bytes
Thank ceilingcat for 6 bytes
```
-Du(x,k)=for(x=~n;x+=2,x<n;putchar(k))
i;j;f(n){u(i,10)u(j,i*i<j*j?32:42);}
```
[Try it online!](https://tio.run/##FcdBCoMwEADA7@xqBJP21DX04kfCQuzGGkUbCIg@3UjnNtwMzKUIBfIQcU8gSreYICippAtVeD/M62mQjjI5iYC7B63/vdh/3bCVpk@Q1YjWzytke0bKtTUqd5GW9OOPW2FEvAE)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 bytes
```
HŻżḂƇṚ$⁾ *xⱮŒḄY
```
[Try it online!](https://tio.run/##ASkA1v9qZWxsef//SMW7xbzhuILGh@G5miTigb4gKnjisa7FkuG4hFn///8xNQ "Jelly – Try It Online")
I'm surprised there wasn't a Jelly answer yet. Jelly is not good at strings.
## Explanation
```
HŻżḂƇṚ$⁾ *xⱮŒḄY   Main monadic link
H                 Halve: n/2
 Ż                Range from 0 to floor(n/2)
  ż               Zip with
      $           (
                    Range from 1 to n
    Ƈ               Filter by
   Ḃ                  parity [to get the odd numbers]
     Ṛ              Reverse
      $           )
           Ɱ      For each pair of numbers
          x         repeat
       ⁾ *            the characters ' ' and '*' that many times
            ŒḄ    Bounce (palindromize)
              Y   Join with newlines
```
]