[Question]
  [
Given a number `N`, how can I print out a Christmas tree of height `N` using the least number of code characters? `N` is assumed constrained to a minimum value of `3`, and a maximum value of `30` (bounds and error checking are not necessary). `N` is given as the one and only command line argument to your program or script.
All languages appreciated, if you see a language already implemented and you can make it shorter, edit if possible - comment otherwise and hope someone cleans up the mess. Include newlines and White Spaces for clarity, but don't include them in the character count.
A Christmas tree is generated as such, with its "trunk" consisting of only a centered "\*"
N = 3:
```
   *
  ***
 *****
   *
```
N = 4:
```
    *
   ***
  *****
 *******
    *
```
N = 5:
```
     *
    ***
   *****
  *******
 *********
     *
```
N defines the height of the branches not including the one line trunk.
**Merry Christmas PPCG!**
  
[Answer]
# Brainfuck, 240 characters
```
              ,
             >++
            +++++
           +[-<---
          --->],[>+
         +++++++[-<-
        ----->]<<[->+
       +++++++++<]>>]<
      [->+>+>>>>>>>+<<<
     <<<<<<]>>>>++++++++
    [-<++++>]>++++++[-<++
   +++++>]+>>>++[-<+++++>]
  <<<<<<[-[>.<-]<[-<+>>+<]<
 [->+<]>>>>>[-<.>>+<]>[-<+>]
>.<<++<<<-<->]>>>>>>>-[-<<<<<
           <.>>>
           >>>]<
           <<<<.
```
Not yet done. It works, but only with single-digit numbers.
EDIT: Done! Works for interpreters using 0 as EOF. See `NOTE`s in commented source for those with -1.
EDIT again: I should note that because Brainfuck lacks a standard method for reading command line arguments, I used stdin (standard input) instead. ASCII, of course.
EDIT a third time: Oh dear, it seems I stripped `.` (output) characters when condensing the code. Fixed...
Here's the basic memory management of the main loop. I'm sure it can be heavily optimized to reduce the character count by 30 or so.
1. Temporary
2. Copy of counter
3. Counter (counts to 0)
4. Space character (decimal 32)
5. Asterisk character (decimal 42)
6. Number of asterisks on current line (1 + 2\*counter)
7. Temporary
8. New line character
9. Temporary?
10. Total number of lines (i.e. input value; stored until the very end, when printing the trunk)
Condensed version:
```
,>++++++++[-<------>],[>++++++++[-<------>]<<[->++++++++++<]>>]<[->+>+>>>>>>>+<<<<<<<<<]>>>>++++++++[-<++++>]>++++++[-<+++++++>]+>>>++[-<+++++>]<<<<<<[-[>.<-]<[-<+>>+<]<[->+<]>>>>>[-<.>>+<]>[-<+>]>.<<++<<<-<->]>>>>>>>-[-<<<<<<.>>>>>>]<<<<<.
```
And the pretty version:
```
ASCII to number
,>
++++++++[-<------>]  = 48 ('0')
Second digit (may be NULL)
,
NOTE:   Add plus sign here if your interpreter uses negative one for EOF
[ NOTE: Then add minus sign here
 >++++++++[-<------>]
 <<[->++++++++++<]>>  Add first digit by tens
]
Duplicate number
<[->+>+>>>>>>>+<<<<<<<<<]>>
Space char
>>++++++++[-<++++>]
Asterisk char
>++++++[-<+++++++>]
Star count
+
New line char
>>>++[-<+++++>]<<<
<<<
Main loop
[
Print leading spaces
-[>.<-]
Undo delete
<[-<+>>+<]
<[->+<]
>>
Print stars
>>>[-<.>>+<]
Add stars and print new line
>[-<+>]
>.<
<++
<<<
-<->
End main loop
]
Print the trunk
>>>>>>>
-[-<<<<<<.>>>>>>]
<<<<<.
Merry Christmas =)
```
[Answer]
# Perl, 50 chars
(1 relevant spaces)
perl: one line version:
```
print$"x($a-$_),'*'x($_*2+1),$/for 0..($a=pop)-1,0
```
and now with more whitesapce:
```
print $"  x ( $a - $_ ),             #"# Syntax Highlight Hacking Comment
      '*' x ( $_ * 2  + 1),
      $/
for 0 .. ( $a = pop ) - 1, 0;
$ perl tree.pl 3
   *
  ***
 *****
   *
$ perl tree.pl 11
           *
          ***
         *****
        *******
       *********
      ***********
     *************
    ***************
   *****************
  *******************
 *********************
           *
$ 
```
### Expanded Explanation for Non-Perl Users.
```
# print $Default_List_Seperator ( a space )  
#     repeated ( $a - $currentloopiterationvalue ) times,
print $" x ( $a - $_ ), 
#"# print '*' repeated( $currentloopiteration * 2 + 1 ) times. 
  '*' x ( $_ * 2  + 1),
# print $Default_input_record_seperator ( a newline )
  $/
# repeat the above code, in a loop, 
#   iterating values 0 to ( n - 1) , and then doing 0 again
for 0 .. ( $a = pop ) - 1, 0;
# prior to loop iteration, set n to the first item popped off the default list, 
#   which in this context is the parameters passed on the command line. 
```
[Answer]
# [J](http://www.jsoftware.com/), 24 characters
`(,{.)(}:@|."1,.])[\'*'$~`
```
   (,{.)(}:@|."1,.])[\'*'$~5
    *    
   ***   
  *****  
 ******* 
*********
    *    
```
Explanation:
```
'*'$~5
*****
[\'*'$~5
*    
**   
***  
**** 
*****
```
Then `}:@|."1` reverses each row and strips off the last column, and `,.` staples it to `]`.
Then `,{.` pastes the first column onto the bottom.
*Previous entries*:
29 characters, no spaces at all.
```
   ((\:i.@#),}.)"1$&'*'"0>:0,~i.3
  *
 ***
*****
  *
   ((\:i.@#),}.)"1$&'*'"0>:0,~i.11
          *
         ***
        *****
       *******
      *********
     ***********
    *************
   ***************
  *****************
 *******************
*********************
          *
```
---
```
   NB. *count from 1 to* n*, then 1 again*
   >:0,~i.3
1 2 3 1
   NB. *replicate '\*'* x *times each*
   $&'*'"0>:0,~i.3
*
**
***
*
   NB. *reverse each row*
   (\:i.@#)"1$&'*'"0>:0,~i.3
  *
 **
***
  *
   NB. *strip off leading column*
   }."1$&'*'"0>:0,~i.3
*
**
   NB. *paste together*
   ((\:i.@#),}.)"1$&'*'"0>:0,~i.3
  *
 ***
*****
  *
```
[Answer]
### Language: Python (through shell), Char count: 64 (2 significant spaces)
```
python -c "
n=w=$1
s=1
while w:
    print' '*w+'*'*s
    s+=2
    w-=1
print' '*n+'*'"
$ sh ax6 11
           *
          ***
         *****
        *******
       *********
      ***********
     *************
    ***************
   *****************
  *******************
 *********************
           *
```
[Answer]
**Language: Windows Batch Script** (*shocking!*)
```
@echo off
echo Enable delayed environment variable expansion with CMD.EXE /V
rem Branches
for /l %%k in (1,1,%1) do (
set /a A=%1 - %%k
set /a B=2 * %%k - 1
set AA=
for /l %%i in (1,1,!A!) do set "AA=!AA! "
set BB=
for /l %%i in (1,1,!B!) do set BB=*!BB!
echo !AA!!BB!
)
rem Trunk
set /a A=%1 - 1
set AA=
for /l %%i in (1,1,!A!) do set "AA=!AA! "
echo !AA!*
```
[Answer]
### Ruby, 64 bytes
```
n=ARGV[0].to_i
((1..n).to_a+[1]).each{|i|puts' '*(n-i)+'*'*(2*i-1)}
```
```
n=$*[0].to_i
((1..n).to_a<<1).each{|i|puts' '*(n-i)+'*'*(2*i-1)}
```
Merry Christmas all!
Edit: Improvements added as suggested by Joshua Swink
[Answer]
### Language: C#, Char count: 120
```
static void Main(string[] a)
{
    int h = int.Parse(a[0]);
    for (int n = 1; n < h + 2; n++)
        Console.WriteLine(n <= h ?
            new String('*', n * 2 - 1).PadLeft(h + n) :
            "*".PadLeft(h + 1));
    }
}
```
Just the code, without formatting (120 characters):
```
int h=int.Parse(a[0]);for(int n=1;n<h+2;n++)Console.WriteLine(n<=h?new String('*',n*2-1).PadLeft(h+n):"*".PadLeft(h+1));
```
Version with 109 characters (just the code):
```
for(int i=1,n=int.Parse(a[0]);i<n+2;i++)Console.WriteLine(new String('*',(i*2-1)%(n*2)).PadLeft((n+(i-1)%n)));
```
Result for height = 10:
```
          *
         ***
        *****
       *******
      *********
     ***********
    *************
   ***************
  *****************
 *******************
          *
```
[Answer]
**python, "-c" trick... @61 chars (and one line)**
```
python -c"for i in range($1)+[0]:print' '*($1-i)+'*'*(2*i+1)"
```
[Answer]
### Language: dc (through shell) Char count: 83
A little bit shorter dc version:
```
dc -e '?d1rdsv[d32r[[rdPr1-d0<a]dsaxszsz]dsbx1-rd42rlbx2+r10Plv1-dsv0<c]dscxszsz32rlbx[*]p' <<<$1
```
EDIT: changed constant 10 into $1
[Answer]
Here's a reasonably space-efficient Haskell version, at 107 characters:
```
main=interact$(\g->unlines$map(\a->replicate(g-a)' '++replicate(a*2-1)'*')$[1..g]++[1]).(read::[Char]->Int)
```
running it:
```
$ echo 6 | runhaskell tree.hs
     *
    ***
   *****
  *******
 *********
***********
     *
```
Merry Christmas, all :)
[Answer]
### Language: dc (through shell), Char count: 119 (1 significant space)
Just for the obscurity of it :)
```
dc -e "$1dsnsm"'
[[ ]n]ss
[[*]n]st
[[
]n]sl
[s2s1[l2xl11-ds10<T]dsTx]sR
[lndlslRxlcdltlRxllx2+sc1-dsn0<M]sM
1sclMxlmlslRxltxllx
'
$ sh ax3 10
          *
         ***
        *****
       *******
      *********
     ***********
    *************
   ***************
  *****************
 *******************
          *
```
[Answer]
Better C++, around 210 chars:
```
#include <iostream>
using namespace std;
ostream& ChristmasTree(ostream& os, int height) {
    for (int i = 1; i <= height; ++i) {
        os << string(height-i, ' ') << string(2*i-1, '*') << endl;
    }
    os << string(height-1, ' ') << '*' << endl;
    return os;
}
```
Minimized to 179:
```
#include <iostream>
using namespace std;ostream& xmas(ostream&o,int h){for(int i=1;i<=h;++i){o<<string(h-i,' ')<<string(2*i-1,'*')<<endl;}o<<string(h-1,' ')<<'*'<<endl;return o;}
```
[Answer]
Language: python, no tricks, 78 chars
```
import sys
n=int(sys.argv[1])
for i in range(n)+[0]:print' '*(n-i)+'*'*(2*i+1)
```
[Answer]
### Language: Java, Char count: 219
```
class T{ /* 219 characters */
  public static void main(String[] v){
    int n=new Integer(v[0]);
    String o="";
    for(int r=1;r<=n;++r){
      for(int s=n-r;s-->0;)o+=' ';
      for(int s=1;s<2*r;++s)o+='*';
      o+="%n";}
    while(n-->1)o+=' ';
    System.out.printf(o+"*%n");}}
```
For reference, I was able to shave the previous Java solution, using recursion, down to 231 chars, from the previous minimum of 269. Though a little longer, I do like this solution because `T` is truly object-oriented. You could create a little forest of randomly-sized `T` instances. Here is the latest evolution on that tack:
```
class T{ /* 231 characters */
  public static void main(String[] v){new T(new Integer(v[0]));}}
  String o="";
  T(int n){
    for(int r=1;r<=n;++r){
      x(' ',n-r);x('*',2*r-1);o+="%n";}
    x(' ',n-1);
    System.out.printf(o+"*%n");
  }
  void x(char c,int x){if(x>0){o+=c;x(c,x-1);}
 }
```
[Answer]
**Groovy** 62B
```
n=args[0]as Long;[*n..1,n].any{println' '*it+'*'*(n-~n-it*2)}
```
\_
```
n = args[0] as Long
[*n..1, n].any{ println ' '*it + '*'*(n - ~n - it*2) }
```
[Answer]
## C# using Linq:
```
    using System;
    using System.Linq;
    class Program
        {
            static void Main(string[] args)
            {
                int n = int.Parse(args[0]);
                int i=0;
                Console.Write("{0}\n{1}", string.Join("\n", 
                   new int[n].Select(r => new string('*',i * 2 + 1)
                   .PadLeft(n+i++)).ToArray()),"*".PadLeft(n));
            }
       }
```
170 charcters.
```
int n=int.Parse(a[0]);int i=0;Console.Write("{0}\n{1}",string.Join("\n",Enumerable.Repeat(0,n).Select(r=>new string('*',i*2+1).PadLeft(n+i++)).ToArray()),"*".PadLeft(n));
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~54~~ ~~53~~ 52 bytes
This is shorter than [@xnor's solution](https://codegolf.stackexchange.com/a/177755/88546) by 4 bytes.
```
i=n=input()
while~i:i-=1;print i%n*' '+~i%n*'**'+'*'
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P9M2zzYzr6C0REOTqzwjMye1LtMqU9fW0LqgKDOvRCFTNU9LXUFduw7M0NJS11bXUv//3wwA "Python 2 – Try It Online")
---
I borrowed @xnor's trick of using modulo (`i%n`) in order to print the trunk on the last line. The next part is figuring out how to print the number of stars.
```
   i   | ~i%n | *2+1 |
-------|------|------|
   5   |   0  |   1  |
   4   |   1  |   3  |
   3   |   2  |   5  |
   2   |   3  |   7  |
   1   |   4  |   9  |
   0   |   5  |  11  |
  -1   |   0  |   1  |
```
The example above illustrates the number of stars we need to print given our variable \$i\$. First, we 'invert' \$i\$ by doing `~i%n`. This gives us an increasing sequence starting from 0. Keep in mind that the way Python handles negative modulo is different from other languages like C.
[Answer]
Improving ΤΖΩΤΖΙΟΥ's answer. I can't comment, so here is a new post. 72 characters.
```
import sys
n=int(sys.argv[1])
for i in range(n)+[0]:
   print ("*"*(2*i+1)).center(2*n)
```
Using the "python -c" trick, 61 characters.
```
python -c "
for i in range($1)+[0]:
   print ('*'*(2*i+1)).center(2*$1)
"
```
I learned the center function and that "python -c" can accept more than one line code. Thanks, 
ΤΖΩΤΖΙΟΥ.
[Answer]
AWK, 86 characters on one line.
```
awk '{s="#";for(i=0;i<$1;i++){printf"%"$1-i"s%s\n","",s;s=s"##"}printf"%"$1"s#\n",""}'
echo "8" | awk '{s="#";for(i=0;i<$1;i++){printf"%"$1-i"s%s\n","",s;s=s"##"}printf"%"$1"s#\n",""}'
        #
       ###
      #####
     #######
    #########
   ###########
  #############
 ###############
        #
cat tree.txt
3
5
awk '{s="#";for(i=0;i<$1;i++){printf"%"$1-i"s%s\n","",s;s=s"##"}printf"%"$1"s#\n",""}' tree.txt
   #
  ###
 #####
   #
     #
    ###
   #####
  #######
 #########
     #
```
[Answer]
**Language:PowerShell, Char count: 41 (including 1 space)**
```
1..$args[0]+1|%{" "*(30-$_)+"*"*($_*2-1)}
```
[Answer]
21 characters with dyalog APL.
```
m,⍨⌽0 1↓m←↑'*'\¨⍨1,⍨⍳
```
⍳ gives a vector of integers starting with 1.
1,⍨ adds a one to the end of the vector. This will be the foot of the tree.
'\*'\¨⍨ gives a vector of \*-strings with lengths given by the previous vector.
↑ transforms the vector to a matrix and adds spaces to the right.
m← stores the matrix in m.
0 1↓ drops zero rows and the first column.
⌽ reverses the matrix.
m,⍨ concatenates with m at the right side.
[Answer]
### Language: C, Char count: 133
Improvement of the C-version. 
```
char s[61];
l(a,b){printf("% *.*s\n",a,b,s);}
main(int i,char**a){
  int n=atoi(a[1]);memset(s,42,61);
  for(i=0;i<n;i++)l(i+n,i*2+1);l(n,1);
}
```
Works and even takes the tree height as an argument. Needs a compiler that tolerates K&R-style code. 
I feel so dirty now.. This is code is ugly.
[Answer]
### Language: C, Char count: 176 (2 relevant spaces)
```
#include <stdio.h>
#define P(x,y,z) for(x=0;x++<y-1;)printf(z);
main(int c,char **v){int i,j,n=atoi(v[1]);for(i=0;i<n;i++){P(j,n-i," ")P(j,2*i+2,"*")printf("\n");}P(i,n," ")printf("*\n");}
```
[Answer]
## R (62 bytes)
I did not see R solution yet. Correct me if I missed it.
```
for(i in c(1:N,1))cat(rep(" ",N-i),rep("*",2*i-1),"\n",sep="")
```
Output:
```
> N <- 3
> for(i in c(1:N,1))cat(rep(" ",N-i),rep("*",2*i-1),"\n",sep="")
  *
 ***
*****
  *
> 
> N <- 4
> for(i in c(1:N,1))cat(rep(" ",N-i),rep("*",2*i-1),"\n",sep="")
   *
  ***
 *****
*******
   *
> 
> N <- 5
> for(i in c(1:N,1))cat(rep(" ",N-i),rep("*",2*i-1),"\n",sep="")
    *
   ***
  *****
 *******
*********
    *
```
[Answer]
## J, 24
Works akin to the [accepted answer](https://codegolf.stackexchange.com/a/4293/3918) in that you include the parameter in the source code. Expressing it as a proper function would be slightly longer. Uses a different approach than the accepted answer.
```
' *'#~(>:@+:,.~#-])0,~i.
```
E.g.
```
   ' *' #~ (>:@+: ,.~ #-]) 0 ,~ i.5
    *    
   ***   
  *****  
 ******* 
*********
    *    
```
As a function (**27**):
```
#&' *'@(>:@+:,.~#-])@,&0@i.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes
```
R”*ẋz⁶ṚŒBṁ‘Y
```
[Try it online!](https://tio.run/##ASQA2/9qZWxsef//UuKAnSrhuot64oG24bmaxZJC4bmB4oCYWf///zU "Jelly – Try It Online")
[Answer]
Shell version, 134 characters:
```
#!/bin/sh
declare -i n=$1
s="*"
for (( i=0; i<$n; i++ )); do
    printf "%$(($n+$i))s\n" "$s"
    s+="**"
done
printf "%$(($n))s\n" "*"
```
[Answer]
### Language: Python, Significant char count: 90
It's ugly but it works:
```
import sys
n=int(sys.argv[1])
print"\n".join(" "*(n-r-1)+"*"*(r*2+1)for r in range(n)+[0])
```
...
```
$ python tree.py 13
            *
           ***
          *****
         *******
        *********
       ***********
      *************
     ***************
    *****************
   *******************
  *********************
 ***********************
*************************
            *
```
[Answer]
# c: 151 116 115
Just giving it a whirl
```
i,j,a;main(c,v)int**v;{for(a=atoi(v[1]);i<a;i+=puts(""))for(j=0;j<a+i;)putchar(++j<a-i?32:42);printf("%*s",a,"*");}
```
Readable code:
```
i, j, a; 
main(c, v) int **v; {
    for (a = atoi(v[1]); i < a; i += puts(""))
        for(j = 0; j < a + i;)
            putchar(++j < a - i ? 32 : 42);
    printf("%*s", a, "*");
}
```
[Try it online!](https://tio.run/##FcxBCsIwEEDRuwwIM0kKWrtyGjyIdDEEqhOwLWnMRjx7TLePzw/dM4Ra1UUn/BZdMLhCumRjCn/nNaF4yatieVwmYh2F1frtk3cEIDqC6M8cR7HK1Dy8JKG1DTq9X/vb0BNvqQ1nhJPZwYkDA8S/WuvwBw)
# Code History:
```
main(int c, char **v){
    int i, j, a = atoi(v[1]);
    for (i = 1; i <= a; i++) {
        for (j = 0; j < a + i - 1; j++)
            putchar((j >= a - i) ? '*' : ' ');
        putchar('\n');
    }
    printf("%*s*\n", a - 1, "");
}
```
[Answer]
# [Poetic](https://mcaweb.matc.edu/winslojr/vicom128/final/index.html), 547 bytes
```
the triangle trees
a december i loved
o,i placed a fun christmasy thing
i know i am hoping on a santa,a gift,cookie plates,or bag o dolls
i know i am choosing my toy to expect of him,Mr.Claus
i say,Mr,i think i may ask nicely
we are nice people,we are
o,under the tree i go crazy as i glance at the a-b-c puzzle we got
a thing on Xmas i am happy to be toying with
o,i found it!for a moment,i shouted thanks
a gift i am having as we enjoy a holiday feast
and now i sleep
oh,here i am,silent as i could
i quickly awaken
i then go to locate a present
```
[Try it online!](https://mcaweb.matc.edu/winslojr/vicom128/final/tio/index.html?VVExUsQwDOzzCtEHZuAL1PS0iqPEJrZlbOfC3eePVW4oKDxjydrV7rp7oV4D5zXaRaQNTLM4SZNUChT1IvOgY6AS2clMTMueyfkaWk/crtR9yOsQaMt6AMCJvBa0SDOGG@fOI9Malj461S2IMXVpo1aaGGM0a4ztH4Pzqs04EvjVDslPEddJF/IhjR/15T3ybqjGV5QQaEI24BNfidtGOTiJ1@EQ4ipnRUW0RBkfLbja8wyX3T@sA7squco3I7AqcgaK@znCz9Ozo7LfbogKFKt2ZHXaN6@f6cSYfy7l1DyJqbf3I3R/prgodlLoTwvsMyVNkjv6zeveEW/3nDf7Awvsj@5iFGDHUslfyIORcQwzjC7CDTLA@QivRZEyqB@9VDnxYwsROx6OnO5xRmjfe3BbBNHBm@TBwpNs7qE6qsP/YEep0oC8v77dJ55/AQ)
Translated from [a version by Daniel Cristofani](http://www.hevanet.com/cristofd/brainfuck/xmastree.b), but optimized specifically for program length in Poetic (more groups of `>` than `<`, more groups of `+` than `-`, etc).
]