text:
Code Golf Christmas Edition: How to print out a Christmas tree of height N
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!

J, 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
  *
 ***
*****
  *

With just 9 more characters you can give this function a name: c=:[:((\:i.@#),}.)"1[:$&'*'"0[:>:0,~i.

What, do you guys use some sort of J documentation library to understandable-ize the code? :)

Brainfuck, 240 characters
              ,
             >++
            +++++
           +[-<---
          --->],[>+
         +++++++[-<-
        ----->]<<[->+
       +++++++++<]>>]<
      [->+>+>>>>>>>+<<<
     <<<<<<]>>>>++++++++
    [-<++++>]>++++++[-<++
   +++++>]+>>>++[-<+++++>]
  <<<<<<[-[>.<-]<[-<+>>+<]<
 [->+<]>>>>>[-<.>>+<]>[-<+>]
>.<<++<<<-<->]>>>>>>>-[-<<<<<
           <.>>>
           >>>]<
           <<<<.

Not yet done.  It works, but only with single-digit numbers.
EDIT: Done!  Works for interpreters using 0 as EOF.  See NOTEs 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.

Temporary
Copy of counter
Counter (counts to 0)
Space character (decimal 32)
Asterisk character (decimal 42)
Number of asterisks on current line (1 + 2*counter)
Temporary
New line character
Temporary?
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 =)

my brain feels f.....sick

Oh my      god.

I found this version online that's only 127 bytes when you delete unnecessary characters.

the stem of the tree has been misaligned for 12 years

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.

Smaller perl implementation of same, only 81 chars
$,="\n";$a=pop;print map{$"x($a-$_).'*'x($_*2+1)}(0...$a-1);print$,.$"x$a."*\n";

Adding $n=$ARGV[0]; at the beginning (cost = 12 chars), then replacing all subsequent occurrences of $ARGV[0] with $n (savings = 6 chars each, times 3 occurrences) will get you a net 6 character reduction in total length.

now 79 chars
$,="\n";$a=pop;print map{$"x($a-$).'*'x($2+1)}0...$a-1;print$,.$"x$a."\n";

64: $,="\n";$a=pop;print map{$"x($a-$).'*'x($*2+1)}0...$a-1,0,-1;

62 $,=$/;$a=pop;print map{$"x($a-$).'*'x($*2+1)}0...$a-1,0,-1;

56: $a=pop;print map{$"x($a-$).'*'x($*2+1).$/}0...$a-1,0;

50, but you need to assume perl -E ( 5.10 ) :  $a=pop;say $"x($a-$).'*'x($*2+1) for 0...$a-1,0;

55, $a=pop;print map{$"x($a-$).'*'x($*2+1).$/}0...$a-1,0;

52: print $"x($a-$),'*'x($*2+1),$/for 0...($a=pop)-1,0

50! print$"x($a-$),'*'x($*2+1),$/for 0..($a=pop)-1,0

Holy crap... perl truly is unreadable.

@zenazn, it seems like that initially, but I would say the same thing about chinese. Once you learn it, it makes perfect sense.

@zenazn, also, it should be noticed that most golfing is BAD code in any language. If this were a competition for the cleanest code, we could win that too.

@zenazn: proof, you can see us collaborating and improving each others code above, this proves WE can read EACH OTHERS code perfectly fine.

PS: Thanks for the explanation for non-Perl programmers. It's still pretty unreadable, but at least it makes sense. I guess you get used to it after a while.

someone tipped me off on this one(outputs to stderr, though)
49: warn$"x($a-$),'*'x($*2+1),$/for 0..($a=pop)-1,0

If you are using Perl 5.10, you could replace print, with say.

Your character count is 49. The space is not significant.

@Kent. Yes, the same way you can get used to count in binary.  10 + 10  - 11 = ( 100 - 11 ) = 1   ... :-/

Perl...Is there nothing he can't do

@zenazn: You haven't seen unreadable until you've seen APL. :-)

@RobH: J is the child of APL.  In some senses, it's more unreadable because it doesn't use APL's character set with a special symbol for every operation -- it overloads ASCII characters with multiple meanings, instead.  http://stackoverflow.com/questions/392788/1088931#1088931

@RobH: You haven't seen unreadable until you've seen Whitespace ( http://en.wikipedia.org/wiki/Whitespace_(programming_language) )

I point out that the J solution is around half this length...

Why did this win when J has smaller char count?

@Claudiu: Look at the dates.  This was accepted long before the J solution was written.

Can be golfed to 44: say$"x($a-$_),"*"x($_*2+1)for 0..($a=<>)-1,0, assuming standard input is allowed instead of command line argument. Otherwise, replace <> with pop and it's 45 chars.

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
           *
          ***
         *****
        *******
       *********
      ***********
     *************
    ***************
   *****************
  *******************
 *********************
           *

what I like most about this solution is that python makes it really hard to write obscure code, it's one of the most readable solutions

You're using the shell to process the argument, which isn't in the spirit of code golf IMO. Using "import sys" and "n=w=int(sys.argv[1])" and an indent of 1 character for the loop body, I come up with 89 characters for this version.

This is how I did it before. The spirit of this question is to have fun, and in addition there was no specification of using only one language :) See the brainfuck answer, for example; no arguments.

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!*

masochist! I like it

Very nice... you get +1

Delayed variable expansion can be enabled using the setlocal enabledelayedexpansion command.

dude. seriously?

Can't make it work. First time I try though.

My answer in batch is much shorter

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

This is a very nice line of Ruby.

Did I seem too abrubt? Sorry, not my intention! Merry XMas! :)

Didn't mean to be mean either, and of course you were right! Merry Xmas!

I recently found the "Try Ruby" webpage, it looks like such a lovely programming language! :)

You can replace +[1] with <<1 and ARGV with $* (-3 characters)

Nice solution. I've translated it to code here http://stackoverflow.com/questions/392788/1089859#1089859

On 1.9, you can save some more chars: n=$*[0].to_i;puts [*1..n,1].map{|i|" "*(n-i)+"*"*(2*i-1)} brings it down to 58.

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:
          *
         ***
        *****
       *******
      *********
     ***********
    *************
   ***************
  *****************
 *******************
          *

python, "-c" trick... @61 chars (and one line)
python -c"for i in range($1)+[0]:print' '*($1-i)+'*'*(2*i+1)"

Actually, it's 57 characters, only the ' ' space is significant as per the question specifications.

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

Good lord, what the hell is that?

Just read man page ;-)

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 :)

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
          *
         ***
        *****
       *******
      *********
     ***********
    *************
   ***************
  *****************
 *******************
          *

Uhm seriously, wtf? I don't understand a single line of that :P

dc is a reverse-polish calculator. 'man dc' is the obvious way to go :)

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) }

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;}

using std; anyone?

strager - when I started there were only a couple std::'s and 'using namespace std;' was a lot of text. I suppose now that would be fewer characters.

Your version is more inefficient than mine, because it has to create strings, my version just prints the characters it needs. :)

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)

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);}
 }

Your new character count is 251 (1 relevant space)

get rid of "public static void main", use a static block and compile with java 6 ;)

I know it's been almost 9 years (lol..) but you can golf some things: class T{public static void main(String[]v){long n=new Long(v[0]),r=1,s;String o="";for(;r<=n;r++){for(s=n-r;s-->0;)o+=' ';for(;++s<2*r;)o+='*';o+="\n";}while(n-->1)o+=' ';System.out.println(o+"*");}} (199 characters/bytes)

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));

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,
ΤΖΩΤΖΙΟΥ.

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
   #
  ###
 #####
   #
     #
    ###
   #####
  #######
 #########
     #

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.

m,⍨⌽0 1↓m← -> (⌽,0 1↓⊢)

Python 2, 54 53 52 bytes
This is shorter than @xnor's solution by 4 bytes.
i=n=input()
while~i:i-=1;print i%n*' '+~i%n*'**'+'*'

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.

Language:PowerShell, Char count: 41 (including 1 space)
1..$args[0]+1|%{" "*(30-$_)+"*"*($_*2-1)}

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.

This has the same problem as my first cut in Java; it isn't a complete program with use of a command-line argument!

Oh? Is this required?
No problem. I'll fix that.

It's 138 characters when all unnecessary newlines are removed.

I count 133 (just removed all whitespace and checked the filesize)

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
            *
           ***
          *****
         *******
        *********
       ***********
      *************
     ***************
    *****************
   *******************
  *********************
 ***********************
*************************
            *

Your character count is 98 (2 significant spaces, those in quotes)

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");}

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" "*"

golfed down to 70 bytes :)

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="")
    *
   ***
  *****
 *******
*********
    *

J, 24
Works akin to the accepted answer 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.

Jelly, 12 bytes
R”*ẋz⁶ṚŒBṁ‘Y

Try it online!

PHP, 111 chars
(The very last char should be a newline.)
<?php $n=$argv[1];for($r='str_repeat';$i<$n;$i++)echo $r(' ',$n-$i).$r('*',$i*2+1)."\n";echo $r(' ',$n).'*' ?>

Readable version:
<?php

$n = $argv[1];

for ($r = 'str_repeat'; $i < $n; $i++)
    echo $r(' ', $n - $i) . $r('*' , $i * 2 + 1) . "\n";

echo $r(' ', $n) . '*'

?>

You can save several characters by building the string, then echoing it.  I think.  Try that out.

Good idea, but I tried it and it only makes it longer. '$t.=(...)' is only one char shorter than 'echo (...)', and then you'd have to 'echo $t' at the end as well.

Shortened it by 4 chars by removing the '$i = 0;' first part of the for statement. PHP assumes that nonexistent variables used in an integer context are 0 already! :P

Saved a char by putting $r=.. inside the for.  Also, I say newline characters should be one byte, not two.  =]

Yeah I just realized I miscounted by one because I counted using the column number in my text editor. I use linux so the newline char is one byte.

Java version. 189 character
class P
{
 static String p(int n, String s)
 {
  return --n < 1 ? s : p(n, s) + s;
 }

 public static void main(String[] a)
 {
  for (int N = new Integer(a[0]), i = -1; i++ < N;)
   System.out.println(p(N - i % N, " ") + p(i % N * 2 + 1, "*"));
 }
}

C# - Recursion
using System;

class A
{
    static string f(int n, int r)
    {
        return "\n".PadLeft(2 * r, '*').PadLeft(n + r)
            + (r < n ? f(n, ++r) : "*".PadLeft(n));
    }

    static void Main(string[] a)
    {
        Console.WriteLine(f(int.Parse(a[0]), 1));
    }
}

177 chars (not as short the other C# method posted, but a different way of doing it).

Charcoal, 9 bytes
Ｇ↗↘←Ｎ*Ｍ↓*

Try it online!
Verbose
Polygon(:UpRight, :DownRight, :Left, InputNumber(), "*")
Move(:Down)
Print("*")

Try it online!

8 bytes

Why is this non-competing?

this was before the rule change to allow languages made after the question; feel free to edit it

05AB1E, 9 bytes
LĆ'*×j€û»

Try it online or verify all Christmas trees in the range [3, 30].
€û» can alternatively be ».º for the same byte-count: try it online.
9 bytes alternative:
·ÅÉĆ'*×.c

Try it online or verify all Christmas trees in the range [3, 30].
Explanation:
L          # Create a list in the range [1, (implicit) input]
           #  i.e. 3 → [1,2,3]
 Ć         # Enclose; appending its own head
           #  → [1,2,3,1]
  '*×     '# For each value, repeat the "*" that many times as string
           #  → ["*","**","***","*"]
     j     # Prepend spaces to make all items of a length equal to the (implicit) input
           #  → ["  *"," **","***","  *"]
      €û   # Palindromize each string
           #  → ["  *  "," *** ","*****","  *  "]
        »  # Join the list by newlines
           #  → "  *  \n *** \n*****\n  *  "
           # (after which it is output implicitly as result)

·          # Double the (implicit) input-integer
           #  i.e. 3 → 6
 ÅÉ        # Pop and push a list of all odd numbers <= this integer
           #  → [1,3,5]
   Ć       # Enclose; appending its own head
           #  → [1,3,5,1]
    '*×   '# For each value, repeat the "*" that many times as string
           #  → ["*","***","*****","*"]
       .c  # Centralize it by adding leading spaces (which implicitly joins by newlines)
           #  → "  *\n ***\n*****\n  *"
           # (after which it is output implicitly as result)

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!
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, "");
}

Welcome to Code Golf! This is good for a first submission; however, I see some easy improvements you can make by simply removing unnecessary spaces and newlines. Also, can you provide a link to test this? It's missing #include<stdio.h> and I'm getting segfaults: link

I think you're getting segfaults because you provided the number as an input rather than an argument link You also don't have to include the #include the compiler will yell at you but it will work. I left in the spaces because the challenge said to count characters ignoring whitespace and it makes it more readable

Oh okay. That makes sense, sorry not a C user :P Thanks for the explanation. And yeah, my bad, I forgot about that part of this challenge (haven't visited it in a while).

You can save another byte with ++j<a-i

K (oK), 33 29 bytes
{(x+1)#(-x+!x)$(1+2*!x)#'"*"}

-4 thanks to streetser!
Try it online!

29 bytes - {(x+1)#(-x+!x)$(1+2*!x)#'"*"}

@streetster, thanks. updated

Can drop another byte by forgoing the $ pad: {" *"(x+1)#(|!x)(&,)'1+2*!x}

Poetic, 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!
Translated from a version by Daniel Cristofani, but optimized specifically for program length in Poetic (more groups of > than <, more groups of + than -, etc).

Scala 3, char count 132 124
@main def t(n:Int)={def p(i:Int,j:Int):Unit={println(" "*i+"*"*j);if(i==0)println(" "*(j/2)+"*");else p(i-1,j+2);};p(n-1,1)}

Readable version
@main def t(n:Int) =
  def p(i:Int, j:Int):Unit =
    println(" " * i + "*" * j)
    if (i == 0) println(" " * (j / 2) + "*")
    else p(i - 1, j + 2)
  p(n - 1, 1)

Results
scala xmastree.scala 3
  *
 ***
*****
  *

scala xmastree.scala 5
    *
   ***
  *****
 *******
*********
    *

Welcome to Code Golf, and nice first answer! Can you shorten your code by removing the spaces/indentation?

Welcome to Code Golf, and nice answer!

In general we score answers in bytes, not characters. In this case the value seems to be the same.

><>, 67 bytes
1:{:v :,2+1{1p461<
v!?:<-1o*84
\~$
>:?!v67*o1-
+:}}\0?;~ao1-::?!v{2

Try it online!

Language: Erlang, Char count: 183 (2 relevant spaces)
Here is an Erlang version, ~181chars:
-module (x).
-export ([t/1]).

t(N) ->
 t(N,0).
t(0,N) ->
 io:format("~s~s~n",[string:copies(" ",N),"*"]);
t(H,S) ->
 io:format("~s~s~n",[string:copies(" ",H),string:copies("*",(S*2)+1)]),
 t(H-1,S+1).

(btw, happy Christmas to everyone!)

Language: C, Char count: 433 (1 relevant space)
C version. Not short, not pretty, but it works.
#include <stdio.h>

void printLevel(int level, int width)
{
    int i;
    int count = level + (level - 1);
    int spaces = width - count;
    int lowerBound = spaces / 2;
    int upperBound = width - lowerBound;
    for (i = 0; i < width; i++) {
        if (i >= lowerBound && i < upperBound) {
            printf("*");
        } else {
            printf(" ");
        }
    }
    printf("\n");
}

void makeTree(int level)
{
    int i;
    int width = level * 2 - 1;
    for (i = 1; i <= level; i++) {
        printLevel(i, width);
    }
    printLevel(1, width);
}

int main(int argc, char **argv)
{
    int level = atoi(argv[1]);
    makeTree(level);
}

Language: Nemerle+Nextem, Char count: 129 (1 relevant space)
Nemerle with Nextem:
type s=string;
module t {
    public Main(a : array[s]) : void {
     def t = int.Parse(a[0]);
     def x(i) { print s(' ',t-i) + s('*',i*2+1) }
     $[0..t].Iter(x);
     x(0)
    }
}

Char count: 128
Edit:  Made it take an arg
Edit2: Imperative now

Language: Scala, Char count: 128 (1 relevant space)
My Scala version.
I'm glad I have found the * operator for strings (String implicitly promoted to RichString).
  def tree(n:Int) {
    def vals(n:Int,k:Int) = ((1 to n) map { i => (k - i, (i * 2) - 1) }).toList
    for(j <- vals(n,n) ::: vals(1,n))
      println(" " * j._1 + "*" * j._2)
  }

Here's how I would do it in Python, very straightforward, only 103 characters:
import sys
n=int(sys.argv[1])
for i in range(n): print ('*'*(2*i+1)).center(2*n)
print '*'.center(2*n)

JavaScript, 110 characters (2 relevant spaces)
function p(l)
{
    o=''
    for(c=0; c<=n+l; c++)
      o += c < n - l ? ' ' : '*'
    print(o)
}

n = parseInt(arguments[0])

for(l = 0; l < n; l++)
  p(l)
p(0)

Ran using spidermonkey.
$ smjs christmas_tree.js 4
For Javascript Console 105
function p(l){o='';for(c=0;c<=n+l;)o+=c++<n-l?' ':'*';console.log(o)}n=+prompt();for(l=0;l<n;)p(l++);p(0)

PHP (133 relevant characters):
function xmastree($h) {
    for($i=0;$i<$h;++$i)
        echo str_repeat(' ',$h-$i-1).str_repeat('*',2*$i+1)."\n";
    echo str_repeat(' ',$h-1)."*\n";
}

Language: C, Char count: 116
I realized I could improve on my original design:
main(int c,char**v){char l[99],i=0;for(c=atoi(1[v]);i<c;printf("%*s%.*s\n",c,l,i++,l))l[i]=42;printf("%*c\n",c,42);}

Different approach (119 characters):
s[99],w,i=0;p(n){printf("%*.*s\n",w+n,n*2+1,s);}main(int c,char**v){w=atoi(v[1]);for(memset(s,42,99);i<w;p(i++));p(0);}

Old version (123 characters):
main(int c,char**v){char*l=calloc(c=atoi(v[1]),2),i=0;for(;i<c;printf("%*s%.*s\n",c,l,i++,l))l[i]=42;printf("%*c\n",c,42);}

(One byte can be saved by putting char *l=... in the for loop.  That makes it non-standard, however (though gcc still accepts it).)

Common Lisp, 117 essential characters:
(defun x (n)
  (dotimes (v n)
    (format t "~v:@<~v{*~}~>~%"
            (1- (* 2 n))
            (1+ (* 2 v))
            '(())))
  (format t "~v:@<*~>~%" (1-(* 2 n)))

Are there any format gurus out there who know a better way to get repeating arbitrary characters?

Language: Php, Char count: 110 (3 relevant spaces)
<?
function x($n,$a,$t){return $n?str_repeat(' ',$n).$a.x($n-1,"*$a"," $t"):$t;}echo x($argv[1],"\n","*\n");
A bit of php recursion to reduce the count of chars to 110.

FreePascal:
program xmastree;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };

var x,y,h:integer;

{$IFDEF WINDOWS}{$R xmastree.rc}{$ENDIF}

procedure printRow(sp,st:integer);
var i:integer;
begin
    for i := 1 to sp do begin
    write(' ');
  end;
    for x := 1 to st do begin
    write('*');
  end;
    for x := 1 to sp do begin
    write(' ');
  end;
    writeln();
end;

begin
    val(ParamStr(1),h);
  for y := 1 to h do begin
    printRow(h-y,(y-1)*2+1);
  end;
  printRow(h-1,1);
end.

Output for xmastree.exe 9
        *
       ***
      *****
     *******
    *********
   ***********
  *************
 ***************
*****************
        *

Windows Batch File
Windows batch files have poor support for string operations: they can concatename, extract and replace strings, but generation of arbitrary-length strings according to a certain pattern AFAIK can only be done via loops. This is how Zach Scrivena's solution works.
However, one can notice that the N+1-th tree line can be generated from the N-th line by cutting one leading space off and adding two traling asterisks, which pretty much simplifies the task. Also, the tree truck repeats the tree top so we can re-use that string to get rid of a few extra loops. So, here's my batch file that uses these two tricks (165 characters):
@echo off
setlocal enableextensions enabledelayedexpansion
set s=
for /l %%i in (1,1,%1)do set s= !s!
set t=!s!*
for /l %%i in (1,1,%1)do echo !t!&set t=!t:~1!**
echo %s%*

Assuming that echo is already off and command extensions and delayed variable expansion are on, we can drop the first two lines and shorten the code down to 108 characters.
Usage:
> xmastree.bat 7 & pause
       *
      ***
     *****
    *******
   *********
  ***********
 *************
       *

Haskell - 105 95 characters - 3 Relevant spaces
Improved on the other Haskell solution (https://codegolf.stackexchange.com/a/4267/7353) by 2 12 strokes.

Updated take x$cycle "*" into replicate x '*'
Removed unnecessary brackets

Updated version:
r=replicate;main=(\x->mapM_ putStrLn[r(x-l)' '++r(l+l-1)'*'|l<-[1..x]++[1]])=<<(readLn::IO Int)

Previous version:
c=cycle;main=(\x->mapM_ putStrLn[(take(x-l)$c" ")++(take(l+l-1)$c"*")|l<-[1..x]++[1]])=<<(readLn::IO Int)

Readable (updated) version:
main=(\ size->
          mapM_
               putStrLn
               [replicate (size - count) ' ' ++ replicate (count + count - 1) '*' | count <- [1..size] ++ [1]]
     ) =<< ( readLn :: IO Int )

Haskell is such an elegant language.

It's in PHP.
<center><?$t=$_GET[1]*2-$i=1;while($i<=$t){echo str_repeat('*',$i).'<br>';$i+=2;}echo'*'?><center>

Total characters(with spaces):98
Total characters(with no spaces):97
Bytes:98

K 33
q)k)f:{{(|:'x),'1_'x}x$(1+(!x),0)#'"*"}
q)f 4
"   *   "
"  ***  "
" ***** "
"*******"
"   *   "

Bash: 126120
As there is no bash purpose, there is one:
for((z=$1-1;z;z--)){ printf -v s "%$((($1-z)*2-1))s" ""
printf "%$((2*$1-z))s\n" "${s// /*}";};printf "%$((1+$1))s\n" \*

This could be written:
#!/bin/bash
               #
              for\
            ((z=$1-
          1;z;z--));do
        printf -v s "%$((
     ($1-z)*2-1))s" "" #fil
   printf "%$((2*$1-z))s\n" \
 "${s// /*}";done;printf "%$((1
          +$1))s\n"\
              \*
              ##

In use:
set -- 12
for((z=$1-1;z;z--)){ printf -v s "%$((($1-z)*2-1))s" ""
printf "%$((2*$1-z))s\n" "${s// /*}";};printf "%$((1+$1))s\n" \*
            *
           ***
          *****
         *******
        *********
       ***********
      *************
     ***************
    *****************
   *******************
  *********************
            *

Or into the script:
./chrismas.sh 6
      *
     ***
    *****
   *******
  *********
      *

another bash solution squished down to 69 bytes :)

nice! Publish, I will give you my upvote!

(U could save 1 char by using \** instead of "**"! ;)

Python - 104 / 94 characters
Alright, so I have two solutions here. One of them is, I guess, a bit "trickier", placing all of the code on one line, while the other solution is actually shorter.
import sys
c=int(sys.argv[1])
for i in range(c+2):print" "*(c-1)+"*"if i==c+1 else" "*(c-i)+"*"*(2*i-1)

That's the 104-char version. Who said python is always readable? It doesn't use any "tricks" though, which is a plus, I guess? If we split the if/else statement onto a seperate line like so:
import sys
c=int(sys.argv[1])
for i in range(c+1):print" "*(c-i)+"*"*(2*i-1)
print" "*(c-1)+"*"

...this is much neater and is actually a few characters shorter.

Python-3x, 119 bytes
N = int(input())
print(' '*N+'\n','\n'.join(['\t'+' '*(N-i)+'*'*(i*2+1) for i in range(N)]) + '\n', ' '*(N+3)+'*'+'\n')

result:-
enter N value
3
   *
  ***
 *****
   *

 4
        *
       ***
      *****
     *******
        *

9
             *
            ***
           *****
          *******
         *********
        ***********
       *************
      ***************
     *****************
             *

Welcome to PPCG! The point of challenges like this one is to provide a solution in as few bytes as possible, so you should include in the title how long it is. (I'd recommend pasting it into this byte counter.) Speaking of which, you could shave off 25 bytes by removing the print statement at the beginning and removing the spaces around the = sign.

Ok, but this is not Python 2.7 anymore, but Python 3. ;) The remaining issue is that your code generates one size smaller tree than specified.

I mentioned it as python-2.7 because in my systems library I have python-2.7 and in my virtualenvironment I have python 3.4. When I execute python 2.7 in the editor I get errors for example if I try end=' ' in the print function if I want to print anything in single line. I import from future to enable print functions which are active in python 3.x versions. Also I have made minor change to represent correct size of tree.

JavaScript (ES6), 58 bytes
f=(n,s=`*
`,l)=>n?(k=' '.repeat(--n)+s)+f(n,'**'+s,l||k):l

Demo

f=(n,s=`*
`,l)=>n?(k=' '.repeat(--n)+s)+f(n,'**'+s,l||k):l

console.log(f(7))

Python 2 - 62 Bytes:
i,x=input()*2,1
exec"print('*'*(x%i)).center(i);x+=2;"*(i/2+1)

Multiplying the input by two saves a byte because of the need for extra brackets.
There may be a way to further golf the operations.

Python 2, 56 bytes
i=n=input()
exec"i=~-i%n;print' '*i+'*'*(n*2-i+~i);"*-~n

Try it online!

Perl 6, 39 bytes
{say " "x$^a-$_,\*x$_*2-1 for 1...$a,1}

Try it online!
It's one of those questions, where it's easier to just print the lines in the code block.
Explanation:
{say " "x$^a-$_,\*x$_*2-1 for 1...$a,1}
{                                     }   # Anonymous code block
                          for 1...$a,1    # Loop over 1 to n and 1 again
 say                                      # Print
     " "x$^a-$_                           # Leading spaces
               ,\*x$_*2-1                 # And then the amount of asterisks

05AB1E (legacy), 16 10 bytes
L·<'**Ć.c»

Try it online!
Explanation:
L·<'**Ć.c»
L          : Create a range [1..input]
 ·<        : 2n-1 every element
   '**     : Multiply every element with "*"
      Ć    : Append the first element to the end
       .c  : Centralize elements
         » : Print out with newlines

Previous solution:
µ¾·>'**¼})Ć.c»

Try it online!
Explanation:
µ¾·>'**I¾-ú¼})Ć»
 ¾·>'**I¾-ú      : Create the row with padding and push to stack
           ¼     : Increment the counter
µ           }    : Loop until the counter reaches the input
             )   : Enclose stack to a list
              Ć  : Append the head to the end
               » : Print out the stack with newlines

No need to mark as noncompeting

Intel 4004 machine code, 59 bytes
This 4-bit chip was the first commercial microprocessor, introduced in 1971. Multiplication and division were performed in software, and the accumulator could not be copied to one of the 16 registers except by swapping values.
40 33 50 0F A0 F8 B0 A0 1C 02 A1 B0 50 0F C0 24
20 A0 F8 50 2B 24 2A A1 90 F5 50 2B 24 20 A0 F8
50 2B 24 0C 53 E0 24 0D 53 E0 C0 14 32 53 E0 F8
40 2B C0 53 F0 B3 B0 A0 B1 50 02

The assembly code requires this python emulator for meaningful output.
jun start

mainloop:
    jms printline
    ld r0
    dac
    xch r0
    ld r0
    jcn an mainloop
    ld r1
    xch r0
    jms printline
    bbl 0

printline:
    fim r2 32
    ld r0
    dac
    jms printx

    fim r2 42
    ld r1
    sub r0
    ral
    jms printx

    fim r2 32
    ld r0
    dac
    jms printx

    ;carriage return
    fim r2 12
    jms $3e0
    fim r2 13
    jms $3e0

    bbl 0

printx:
    jcn az ditch
    jms $3e0
    dac
    jun printx
ditch:
    bbl 0

start:
    jms $3f0 ; input
    xch r3
    xch r0 ; running total
    ld r0
    xch r1 ; permanent total
    jms mainloop

Sample run:
$ python intel4004-emu/main.py tree.4004
8
       *
      ***
     *****
    *******
   *********
  ***********
 *************
***************
       *

Batch, 132 129 bytes
@!! 2>nul||cmd/q/v/c%0 %1&&exit/b
for /l %%X in (1 1 %1)do set[= ![!
set]=![!*
:*
echo%]%
set]=%]:~1%**
2>x goto:*%]:~1%&echo%[%*

I shamelessly copied Golfing Delayed Expansion Variables in Batch to my batch script.
Uses the bizarre ability of GOTO :NUL to

allow execution of concatenated commands in the context of the caller

Edit 2020/5/1: Abused token delimiters to shorten variable names

Vyxal C, 7 bytes
ʁd›×*×J

Try it Online!
Vyxal, 13 bytes
ɾ×*§↵vøm:⁋₴h,

Try it Online!

jq -r, 47 41 39 bytes
-2 bytes thanks to Michael Chatiskatzi
. as$n|range(.),0|" "*($n-.)+"**"*.+"*"

Try it online! Add 2 bytes if a leading space is not acceptable.
. as$n                                   Store the input number in $n
      |                                  With that number as .
       range(.)                           Numbers from 0 up to one less than .
               ,0                         and also another 0
                 |                       With each of those numbers as .
                     *($n-.)              $n minus . copies of
                  " "                     space
                            +             Concatenate
                                 *.       . copies of
                             "**"         that string
                                   +"*"   Concatenate one more asterisk

The -r flag outputs each of those strings on a separate line without wrapping it in quotes.

range(.),0 will save 2 bytes.

Language: Python, Char count: 104
Another take at python. Note that the question requested for a script, not a function.
import sys
n= int(sys.argv[1])
c= lambda s: s.center(2*n)
print "\n".join(c("*"*(2*i+1)) for i in range(n)); print c("*")

$ py ax 11
          *
         ***
        *****
       *******
      *********
     ***********
    *************
   ***************
  *****************
 *******************
*********************
          *

First try in LUA
f=string.rep p=print function t(N) for i=0,N do s=f(" ",N-i) p(s..f("+",2*i-1)..s) end p(f(" ",N-1).."+"..f(" ",N-1)) end t(arg[1])

After selecting all of it scite tells me these are 131 chars
For clarities sake without optimizing away the \n etc:
f=string.rep
p=print
function t(N)
 for i=0,N do
   s=f(" ",N-i)
   p(s..f("+",2*i-1)..s)
 end
  p(f(" ",N-1).."+"..f(" ",N-1))
end
t(arg[1])

For the python version by ΤΖΩΤΖΙΟΥ I get shown 115 chars... Hrm, some more things to optimize

Note: all insignificant/irrelevant whitespace should be ignored, as per the question specifications. So, any beautifying/syntax-needed whitespace doesn't count, but a " " literal does count. So your fully expanded version has 119 chars (3 significant spaces)

Scala, 97 chars
This one gets n from command line.
Thanks to ΤΖΩΤΖΙΟΥ for the * operator
val n=args(0).toInt*2
(1.until(n,2))foreach{i=>println(" "*(n-i)+"* "*i)}
println (" "*(n-1) + "*")

Language: Pike
101 Relevant characters
int main (int c, array a) {
    int n=(int)a[1], i,l;
    for(;i<=n; l = ++i < n ? i : 0)
        write(" " *(n-l) + "*" * (l*2+1) +"\n");
}

Rhino Javascript shell: 117 chars minified
t=['*'];
for(i=1;i<arguments[0];++i)
{
  s='*'+t[i-1]+'*';
  for(j in t)
    t[j]=' '+t[j];
  t[i]=s;
}
t[i]=t[0];print(t.join('\n'));

minified:
t=['*'];for(i=1;i<arguments[0];++i){s='*'+t[i-1]+'*';for(j in t) t[j]=' '+t[j];t[i]=s;}t[i]=t[0];print(t.join('\n'));

results:
c:\>java -jar C:\appl\Java\rhino1_7R1\js.jar c:/tmp/Xtree.js 10
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
         *

Language: FoxPro 2.x for DOS (should work with Clipper too), Char count: 62
para n
for h=1 to n
?spac(n-h)+repl('*',2*h-1)
endf
?spac(n-1)+'*'

Language: Euphoria  147 chars (9 relevant spaces):
include get.e
object
    a = command_line(),
    t = 42
a = value( a[3] )
a = a[2]
for i = 1 to a do
    puts(1, repeat( 32, a - i ) & t & 10)
    t &= "**"
end for
puts(1, repeat( 32, a - 1 ) & 42 & 10 )

With only relevant whitespace:
include get.e
object a=command_line(),t=42a=value(a[3])a=a[2]for i=1to a do puts(1,repeat(32,a-i)&t&10)t&="**"end for puts(1,repeat(32,a-1)&42&10)

Excessively long version in J (97 chars)
t=:3 :0
d=:0
k=:''
while.d<y
do.
k=:k,((d{((y-1)+>:i.y))$!.'*'((d{((|.i.y)))$,' ')),LF
d=:d+1
end.k,y$k
)

Run it this way:
t N

where N is tree height.
And Merry Xmas (a bit late).

I got it in 29 characters: http://stackoverflow.com/questions/392788/1088931#1088931

C# 3.0, 158 bytes
int n=int.Parse(a[0]);Console.WriteLine(Enumerable.Range(1,n).Concat(new int[]{1}).Select(x=>new string('*',x*2-1).PadLeft(x+n)).Aggregate((x,y)=>x+"\n"+y));

Ungolfed:
using System;
using System.Linq;
class Program
{
    static void Main(string[] a)
    {
        int n = int.Parse(a[0]);
        Console.WriteLine(Enumerable.Range(1, n).Concat(new int[] { 1 })
            .Select(x => new string('*', x * 2 - 1).PadLeft(x + n))
            .Aggregate((x, y) => x + "\n" + y));
    }
}

VBScript, 106 characters
n = WScript.Arguments(0)
For i = 1 To n
  WScript.Echo Space(n-i+1) & String(2*i-1, "*")
Next
WScript.Echo Space(n) & "*"

Usage and output example:
> cscript christmastree.vbs 7 //nologo
       *
      ***
     *****
    *******
   *********
  ***********
 *************
       *

Here's a Ruby Newbie (ha! It rhymes!) with his first working solution:
Ruby 164 characters (of readable code)
n=gets.to_i-1
(0..n).each do |j|
    (n-j).times do
        print " "
    end
    (1+j*2).times do
        print "*"
    end
    print "\n"
end
n.times do
    print " "
end
print "*"

Lua, 113 significant chars
s=string.rep;n=tonumber(arg[1]);r=print;for i=0,n do l=s(" ", n-i)..s("*",(n-(n-i))*2+1);r(l)end r(s(" ",n).."*")

The two ns in s("*",(n-(n-i))*2+1) can be canceled out, yielding s("*",i*2+1).

Golfscript - 27 chars
~:i,0+{.i\-(' '*\.)+'*'*n}%

~:i  # eval the command line arg, store in i
,0+  # create a list [0..i-1] add 0 to the end
{}%  # map this block over the list
.    # make a copy of the list element
i\-  # subtract the list element from i
(    # decrease by one more
' '* # multiply the result by ' '
\    # swap, so the list element is back on top of stack
.)+  # duplicate, add one, add the two numbers together
'*'* # multiply the result by '*'
n    # put a newline here

nice, i did mine before seeing yours, was about to refactor it to look like this

C++, 188 bytes
#include<iostream>
using namespace std;
#define s string
int main(int a,char**c){int h=atoi(c[1]);for(int i=0;i<h;i++){cout<<s(h-i,' ')<<s(i*2+1,'*')<<endl;}cout<<s(h,' ')<<'*'<<endl;}

Ungolfed:
#include<iostream>

using namespace std;

int main(int a,char**c)
{
    int h = atoi(c[1]);
    for(int i=0; i<h; i++)
    {
        cout << string(h-i, ' ') << string(i*2+1, '*') << endl;
    }
    cout << string(h, ' ') << '*' << endl;
}

Q, 54
{-1(-:)[((x+(!)x),x)]$(((&)((!)(2*x))mod 2),1)#\:"*";}

example:
q){-1(-:)[((x+(!)x),x)]$(((&)((!)(2*x))mod 2),1)#\:"*";} 10
         *
        ***
       *****
      *******
     *********
    ***********
   *************
  ***************
 *****************
*******************
         *

This is my first experience with code golf. So advices are welcome :)
C: 170 chars:
int main(){
    int n,m=1,x;
    scanf("%d",&n);x=2*n-1;
    for(;m<x*n+n+2;m++)
        printf("%c",m==x*n|m==x*n+n+1?42:m==x*n+1?10:m>x*n?32:!(m%(2*n-1))?10:!(m%x<n-m/x)&m%x<m/x+n+1?42:32);
}

I did not see a solution using R.  The code below may not be efficient, but it seems to work (170 characters with spaces if all code placed on one line):
for(i in 1:4){ cat( paste( paste(rep(' ', (3-(i-1))), collapse=''),
                           paste(rep('*', (2*i-1)),   collapse=''), collapse=''),
               sep='\n'); if(i==4) cat('    *    ', sep='\n')}

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

Javascript, 89
i=4
c=t=""
while(i){o=c,j=(i--+1)*2-3
while(j--)o+="*"
t=o+"\n"+t
c+=" "}console.log(t+o)

Javascript 81
o=s=''
for(a=3;a--;){l=s+=' '
for(k=a*2+1;k--;)l+='*'
o=l+'\n'+o}console.log(o+l)

Scala, 73 chars
val n=args(0).toInt
(1 to n):+1 foreach(i=>println(" "*(n-i)+"*"*(2*i-1)))

run as
golf.scala 10

Wait, does that display the trunk?

yes, :+1 would do that

><>: 136 chars
This one's not going to win, but because Christmas is coming again, I thought fish needed a Christmas tree too! (pun intended)
1-:&1$>:> :1(?!v~$:> :1(?!vv
        ^-1o" "<   ^-1o"*"<>~2+$1-:0(?!v~~&ao>" "o1-v
      ^                              oa<;o"*"^!?(1: <

It can be run as follows with the standard interpreter:
./fish.py christmas.fish -v 5

... for N=5. (If the file is called christmas.fish :P) In this way, one prepopulates the stack with the value 5. This is the closest I could get to a command-line argument.

Dart, 174 characters
main(p){var x=-1,r='',a=int.parse(p[0]),b=a,f=(x,y,[z='']){var s='';while(x-->0)s+=y;return s+z;};while(a-->0){x+=2;r+=f(a,' ')+f(x,'*','\n');}print('$r${f(b-1,' ','*')}');}

R, 94 chars
Christmas is over, but anyway:
t=function(N){
  f=function(i)cat(rep(" ",N-i),rep("*",2*i-3),"\n",sep="")
  lapply(2:N,FUN=f);f(2)
}

For trees of height 2 or more:
> t(2)  > t(3)  > t(5)
*        *         *
*       ***       ***
         *       *****
                *******
                   *

We have posted similar R solutions in three minutes ;)

becomes obsolete, see @djhurio solution

btw, I have got attracted to this site by the "2014" problem. I have got a 20 chars solution in R, but cannot post it as the question is protected from newbies ;)

Would be nice to see your 20 char solution for the "2014" ;)

sum(T+T:exp(T+pi))-T

Nice one. Should I add it to my answer mentioning you as an author?

done, see: http://codegolf.stackexchange.com/a/17877/13849

Japt, 11 bytes
õ_ç* êÃp* û

Try it online!

APL(NARS), 37 chars, 74 bytes
{⊃⍵{(' '⍴⍨⍺-⍵),'*'⍴⍨1+⍵×2}¨0,⍨0,⍳⍵-1}

test:
  h←{⊃⍵{(' '⍴⍨⍺-⍵),'*'⍴⍨1+⍵×2}¨0,⍨0,⍳⍵-1}
  h 5
     *
    ***
   *****
  *******
 *********
     *
  h 1
 *
 *
  h 2
  *
 ***
  *
  h 3
   *
  ***
 *****
   *

Ot: It seems that your sys for know if i'am a human not work good in this chellphone (so I write this because possible this step is not taken)

PHP, 79 bytes
while($argn)echo$r[]=str_pad("
",1+$argn--).str_pad("",++$n*2-1,"*");echo$r[0];

Run as pipe with -nR or try it online.

Save 2 bytes using variable variables: Try it online!

Japt -R, 11 bytes
ÇÑÄ î*Ãp* û

Try it
Ç               :Map the range [0,input)
 Ñ              :  Multiply by 2
  Ä             :  Add 1
    î*          :  Repeat * that many times
      Ã         :End map
       p*       :Push a *
          û     :Centre pad each element with spaces to the length of the longest
                :Implicitly join with newlines

Lua, 100 99 bytes
p,r,n=io.write,('').rep,arg[1]for i=0,n do p(r(' ',n-i+1),r('*',i*2+1),'\n')end p(r(' ',n+1),'*\n')

Try it online!
Another Lua version, a little shorter.

Python3,81 bytes
n=int(input());
for j in range(n):
 print(' '*(n-j)+'*'*(2*j+1))
print(' '*n+'*')

try it online

79 bytes

Zsh, 77 64 bytes
Since all these old questions are now open, I think the oldest q. on codegolf.se needs a zsh answer!
Try it Online!
s=*;for ((;i<$1;))printf %$[$1+i++]s\\n $s&&s+=**
printf %$1s \*

Hat-tip to Alastair from Boxing Day 2008
NB: Putting the printf stuff in a function is no advantage...
NB2: original for 77 bytes.. saved 12 bytes by eliminating quotes, braces, trailing newline

Wren, 91 bytes
Fn.new{|n|
for(i in 0...n)System.print(" "*(n-i)+"*"*(2*i+1))
System.print(" "*n+"*")
}

Try it online!

Keg, 42 38 32 23 bytes
:&1ɧ1⑷:⑻$-⑬*$⑵;`*`*⑸(
'

Try it online!
-9 bytes due to generating odd numbers inside of the map
Answer History
32 Bytes
¿&1(⑻|:2+)1^⑷:;½ℤ⑻$-⑬*^`*`*⑸(,
,

Try it online!
-6 bytes due to using a mapping approach
38 Bytes
:&®l1(©l|⑬©l*,:`*`*,
,2+©l;®l)&⑬*,`*`,

-4 bytes due to ⑬ operator (space string)
Funny story: I almost said this was 40 bytes before I realised that I forgot how to count.
Try it online!
I might as well place up the Keg Christmas tree for the year seeing as how it's almost December!
Explained
:&®l    #Store the amount of lines in variable l and the register
1   #Push the number of stars per row
(©l|    #Repeat variable l times
    ⑬©l*,   #Print that amount of spaces
    :`*`*,  #Print that amount of stars

    ,   #Print a literal newline
    2+  #Increment the number of stars
    ©l;®l   #Update the amount of spaces to print
)
&⑬*,`*`,    #Print the bottom row

Charcoal, 12 bytes
Ｇ<Ｎ*‖↑¶Ｍ⊖θ←*

Try it online
explanation
Ｇ<Ｎ*             #Draw a triangle size input N with character "*"
      ‖↑           #Mirror the triangle so it is the right way round
        ¶          #Newline
         Ｍ⊖θ←    #move left input-1
               *   #"*" character
                   #the result is implicitly printed

Nice answer! I took the liberty of creating a TIO link so others can see it in action, if you'd liked to edit it into your post: https://tio.run/##ASkA1v9jaGFyY29hbP//77ynPO@8ririgJbihpHCtu@8reKKls644oaQKv//NQ

my bad @Malivil! I meant to add one, but forgot, thank you :)

Java, 180 chars
interface a{static void main(String[]a){for(int N=new Byte(a[0]),i=-1;i++<N;p('*',i%N*2),p('\n',0))p(' ',N-i%N-1);}static<T>void p(T c,int i){System.out.print(c);if(i-->0)p(c,i);}}

I believe this is a new record for Java for this question!
interface a
{
    static void main(String[]a){
        for(int N=new Byte(a[0]),i=-1;i++<N;p('*',i%N*2),p('\n',0))p(' ',N-i%N-1);
    }
    static<T>void p(T c,int i){
        System.out.print(c);
        if(i-->0)p(c,i);
    }
}

This program uses a recursive method to get rid of unnecessary for loops and print calls. Everything in main is run in one for loop.

The whitespace is there to make it easier to read. The 180 char count is for the necessary characters only.

Nice. I see that you have already included the reduced version as well.  That would have been what I suggested, and it is generally best to include both versions.

Pip, 18 bytes
@PPZsXa-_.'*X_M\,a

Try it online!
I don't know how pip recognizes this lambda, but it somehow does.
-3 from DLosc.
Explanation
YPPZsXa-_.'*X_M\,ay@0 a → input
              M\,a    map inclusive range of 0 - a, loop var '_'
    sXa-_             repeat space (input - _) times
         .'*X_        repeat * _ times
         .            join them:
  PZ                  palindromize the result: ' ***' → ' ***** '
YP                    print each item of the array with newline
                      and assign the array to variable y
                  y@0 return first element of y (always a single *)
                      implicitly print it

@y cannot be used here, since it changes \,a in the first statement.

Nice! Here's 18 bytes, taking advantage of the fact that P returns its operand.

MAWP, 45 bytes
=M@![![32;1-]`M[42;1-]`M2+=M10;1-]`[32;1-]42;

Try it!
Takes a while for N bigger than 10

Rockstar, 107 bytes
listen to N
X's0
while N-X
let X be+1
let Y be N-X
let Z be X*2-1
say " "*Y+"*"*Z

let N be-1
say " "*N+"*"

Try it here (Code will need to be pasted in)

A good idea would be to append the name of a related rock song to each of your rockstar programs.

Not a bad idea, @Razetime, I might just do that - I already use song names for all my challenge titles. Of course, if I was anyway skilled at such things, I'd actually write a song in Rockstar related to the challenge!

sed 4.2.2, 62 bytes, -r flag
s/0\B/ /g
:
H
s/ (0+)/0\10/
//b
:a
s/0(0+)0/ \1/
ta
H
x
y/0/*/

Takes input in unary (e.g. 3 is 000), allowed as per meta consensus.
Try it online!
With comments:
#Replace all zeroes except the last by a space
s/0\B/ /g
#Unnamed branch label
:
#Append to hold buffer
H
#Put zeroes around a stretch of zeroes
s/ (0+)/0\10/
#Jump to unnamed label if there are any spaces left
//b
#Create a label a, and recursively remove initial/final zeroes
:a
s/0(0+)0/ \1/
ta
#Append to hold buffer
H
#Exchange hold/pattern buffers
x
#Replace 0s with asterisks
y/0/*/

Ruby 2.7, 50 bytes
->h{t=(0...h).map{" "*(h-_1)+?**(_1*2+1)};t<<t[0]}

Try it online!
TIO uses an older version of Ruby, whereas in Ruby 2.7, we've numbered parameters, which saves a byte.

Clojure, 214 bytes
(defn p[n](let[c(map #(inc(* % 2))(range n))l(map #(apply str %)(partition 2(interleave(map #(apply str(repeat(/ % 2)" "))(reverse c))(map #(apply str(repeat % "*"))c))))](doseq[a l](println a))(println(first l))))

Try it online!
Ungolfed:
(defn print-xmas-tree-of-height [n]
  (let [asterisk-counts       (map #(inc (* % 2)) (range n))
        asterisk-strings      (map #(apply str (repeat % "*")) asterisk-counts)
        leading-spaces        (map #(apply str (repeat (/ % 2) " ")) (reverse asterisk-counts))
        lines                 (map #(apply str %) (partition 2 (interleave leading-spaces asterisk-strings)))
        ]
    (doseq [aLine  lines]
      (println aLine))
    (println (first lines))))

I think you can make this a lambda instead of a named function

@Seggan You can't use #() because you can't nest them, but you could do (fn[n](...))

Raku, 50 48 46 bytes
(45 characters, but » is 2 bytes)
{(|^$^n,0)».&{printf "%{$n+$_}s
",\*x$_*2+1}}

Try it online!
Original 50-byte version:
-> \n{(|^n,0)».&{printf "%{n+$_}s
",'*'x 2*$_+1}}

48-byte version:
-> \n{(|^n,0)».&{printf "%{n+$_}s
",\*x$_*2+1}}

'*' can be \*, instead of -> \n you can use a placeholder parameter ($^n) and you can rarrange the 2*$_+1 to have $_ first to save that space

@jo Thanks! But I don't think I can use a placeholder, because I'm using it inside a nested block.

You can, just don't add the ^ to the second instance of $n, like {(|^$^n,0)».&{printf "%{$n+$_}s ",\*x$_*2+1}}

Oh! Well, then. Thanks again!

Language: Erlang, Char count: 151
A little bit shorter Erlang version:
-module(x).
-export([t/1]).
t(N)->[H|_]=T=t(N,1),io:format([T,H]).
t(0,_)->[];t(N,M)->[[d(N,32),d(M,42),10]|t(N-1,M+2)].
d(N,C)->lists:duplicate(N,C).

When should run with command line argument
-module(x).
-export([t/1]).
t([N])->[H|_]=T=t(list_to_integer(N),1),io:format([T,H]),init:stop().
t(0,_)->[];t(N,M)->[[d(N,32),d(M,42),10]|t(N-1,M+2)].
d(N,C)->lists:duplicate(N,C).

Invocation:
$ erl -noshell -noinput -run x t 11
           *
          ***
         *****
        *******
       *********
      ***********
     *************
    ***************
   *****************
  *******************
 *********************
           *

GolfScript, 34 characters
Another GolfScript entry:
~:x,-1%[x(]+{." "*x@- 2*("*"*n.},;

Explanation:
~:x                   #read input, store into x
,                     #create array [0,1,2,...,x-1]
-1%                   #reverse it
[x(]+                 #append x-1 to the array
{." "*x@- 2*("*"*n.}, #map each element in array to this block, outputs each line
;                     #remove results of map from stack

The block does:
{.                    #duplicate value given by map (stack is now: i i)
" "*                  #push " ", times it by i (stack now: i "   ")
x                     #push x, stack is: (i "   " x), and bring i
@                     #bring i to the front (stack is: "   " x i)
- 2*(                 #pop x,i, push ((x-i)*2-1)
"*"*                  #print that many *'s
n.}                   #print newline, duplicate it so the map doesn't kill it

JavaScript, 137 bytes
function k(a){var b="";for(i=0;i<a;i++){for(j=0;j<a*2;j++)b+=j>a-2-i
&&j<a+i?"*":" ";b+="\n"}for(i=0;i<a*2;i++)b+=i==a-1?"*":" ";return b}

Test case (formatting disorder is due to the first " marking a string):
k(3)

"  *
 ***
*****
  *   "

Python 2, 119 116
This one generates the tree on one line:
import sys
h=int(sys.argv[1])
print '\n'.join([" "*(h-i)+"*"*(i*2-1) for i in range(h,0,-1)][::-1]+[" "*(h-1)+"*"])

It's too bad you have to import the sys module in Python before being able to read argv.
Being used from Command Prompt:
C:\Users\User4\Desktop>treeprint.py 6
     *
    ***
   *****
  *******
 *********
***********
     *

I have a Linux box but it can't connect to the Internet and only has Python 2.4, in case you're wondering why I'm using Windows.

SOGL V0.12, 11 10 bytes
ƨ*αak} *¹╚

Try it Here!
Explanation:
     }      implicitly started loop, repeated input times
ƨ*          push "**"
  α         append that to the variable A, here defaulted to an empty string
   a        load the variable A
    k       remove the first characters
       *    push "*"
        ¹   wrap in an array
         ╚  center horizontally

Excel VBA, 72 Bytes
Anonymous VBE immediate window function that takes input from range [A1] and outputs to the VBE immediate window
For i=1To[A1]:[B1]=i:?Spc([A1]-i)[Rept("*",2*B1-1)]:Next:?Spc([A1-1])"*"

Python 3, 83 bytes
f=lambda n:'\n'.join([' '*(n-1-i)+'*'*(i*2+1)for i in range(n)])+'\n'+' '*(n-1)+'*'

JavaScript, 90 89 bytes
f=(l,n=1,s="")=>l+1?s+=f(l-1,n+2,l?`*`.repeat(n).padStart(l+n)+`
`:"*".padStart(n/2+1)):s

Try it online!

Alternative:
f=(l,n=1)=>l+1&&f(l-1,n+2,console.log(l?"*".repeat(n).padStart(l+n):"*".padStart(n/2+1)))

Try it online!

There's a padStart function in JavaScript?? And who says you never learn anything useful in CodeGolf...

x86 machine code, 42 40 bytes
Same limitation as in previous x86 answer (N < 10) applies. It may be lifted by replacing the first four lines with the following six (+6 bytes):
start:
    mov si, 82h
    lodsw
    xchg al, ah
    and ax, 0F0Fh
    aad

Assembly source code:
start:
    mov si, 82h
    lodsb
    aaa
    xchg ax, cx
    mov dx, 0A2Ah
    mov di, dx
    push cx
_loop:
    push cx
    rep stosb
    xchg ax, dx
    mov cx, bx
    rep stosb
    stosw
    inc bx
    inc bx
    pop cx
    xchg ax, dx
    loop _loop
    pop cx
    rep stosb
    xchg ax, dx
    stosw
    xchg ax, dx
    mov ax, 0924h
    stosb
    int 21h
    ret

SmileBASIC, 55 Bytes
Takes input from variable 'N'
FOR I=1TO N?" "*(N-I);"*"*(1+(I-1)*2)NEXT?" "*(N-1);"*"

I think it may be possible to shorten line 2 or 3 in the breakdown below
FOR I=1TO N                                                Iterate values of 'I' from 1 to N (One for each layer of branches)
           ?" "*(N-I)                                      Display spaces to offset asterisks, which begins at N-1 spaces long and end at 0 spaces long
                     ;"*"*(1+(I-1)*2)                      Display Asterisks
                                     NEXT                  End loop
                                         ?" "*(N-1);"*"    Display trunk

SAS, 70 87 bytes
87 bytes. With a pop window for N input.
data;
window _ n;
display _;
do i=1to n;
s=repeat('*',i*2-2);
put@(n-i+1)s;
end;
put@n'*';
run;

70 bytes. Imperfect, need to assign to N handly.
data;
n=9;
do i=1to n;
s=repeat('*',i*2-2);
put@(n-i+1)s;
end;
put@n'*';
run;

The result is
        *
       ***
      *****
     *******
    *********
   ***********
  *************
 ***************
*****************
        *

Do you have a link to this language? Is there really no way to take input?

@JoKing It is relatively rarely used. SAS is a language to do statistical analysis.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/2.5/


text:
Check if a string is a shuffle of twins
Explanation
Two strings can be shuffled by interspersing their letters to form a new string, much like two piles of cards can be shuffled to form a single pile.
For example, the strings HELLO and WORLD can be shuffled to form HWEOLRLLOD, or HEWORLLLDO, or perhaps simply HELLOWORLD.
It is not a shuffle if the original order of letters is not preserved. For example, the D in WORLD cannot ever appear before the R after being shuffled. This means that EHLLOWRDLO, for instance, is not a shuffle of HELLO and WORLD, even though it contains all the original letters.
A string is a shuffle of twins if it can be formed by shuffling two identical strings. For example, ABACBDECDE is a shuffle of twins because it can be formed by shuffling ABCDE and ABCDE. DBEACBCADE is not a shuffle of twins because it cannot be formed by shuffling two identical strings.
Program Details
Given an input string, output 0 if it is not a shuffle of twins, and output one of the twin strings if it is a shuffle of twins.
You may assume that the input string has a length inclusively between four and twenty characters and is composed entirely of uppercase alphabetic characters. It should be able to run in a reasonable amount of time, say, under 10 minutes.
This is code golf, so the shortest solution wins.
Example I/O
> ABACBDECDE
ABCDE

> DBEACBCADE
0

> FFFFFF
FFF

> FFGGG
0

> ABBA
0

> AABB
AB

> AABAAB
AAB

I have an example (non-golfed) implementation.

Example string FGG violates assertion that the input string has a length inclusively between four and twenty characters, and don't tell me "never trust user input!", "never trust the specs!"

@userunknown That is so embarrassing! I edited it to FFGGG to make it consistent.

Just out of curiosity, can anyone come up with a solution with sub-exponential worst case time complexity, or prove that there isn't any?

Haskell, 114
main=getLine>>=putStrLn.f.p;f x=head$[a|(a,b)<-x,a==b]++["0"]
p[]=[([],[])];p(x:y)=do(a,b)<-p y;[(x:a,b),(a,x:b)]

Ungolfed:
main :: IO ()
main = getLine >>= putStrLn . findMatch . partitions

-- | Find the first partition where the two subsequences are
-- equal. If none are, return "0".
findMatch :: [(String, String)] -> String
findMatch ps = head $ [a | (a,b) <- ps, a == b] ++ ["0"]

-- | Return all possible partitions of the input into two
-- subsequences. Preserves the order of each subsequence.
--
-- Example:
-- partitions "AB" == [("AB",""),("B","A"),("A","B"),("","AB")]
partitions :: [a] -> [([a], [a])]
partitions []     = [([], [])]
partitions (x:xs) = do (a, b) <- partitions xs
                       [(x:a, b), (a, x:b)]

Explanation:
Most of the work is being done in the partitions function. It works by
recursively generating all partitions (a, b) of the tail of the list,
and then using the list monad to prepend the initial element x to each of
them and gather all the results.
findMatch works by filtering this list so that only partitions where the
subsequences are equal remain. It then returns the first subsequence in the first
partition. If none remain, the list is empty, so the "0" appended at the
end gets returned instead.
main just reads the input, feeds it through these two functions and prints it.

For those of us who can't read Haskell, will you give an explanation?

@Mr.Wizard: See edit.

I think I came up with something fairly similar, though not as short, but I threw in a foolish sort that made it a complete failure.  Do you mind if I implement this algorithm in Mathematica?

R, 113 chars
l=length(x<-charToRaw(scan(,'')));max(apply(combn(l,l/2),2,function(i)if(all(x[i]==x[-i]))rawToChar(x[i])else 0))

Ungolfed (and instead a function that takes the string):
untwin <- function(x) {
  x <- charToRaw(x)
  indMtx <- combn(length(x),length(x)/2)
  res <- apply(indMtx, 2, function(i) {
    if (all(x[i]==x[-i]))
      rawToChar(x[i])
    else
      0
  })
  max(res)
}

untwin("ABACBDECDE") # "ABCDE"
untwin("DBEACBCADE") # 0

The solution relies on the combn function that generates all combinations of indices as columns in a matrix. apply then applies a function to each column (dimension 2) in the matrix and returns a vector of strings or zeroes. max then find the biggest string (which trumps 0).
A cool feature in R is the ability to select a subset of a vector given a vector of indices, and to then select the complement of that subset by negating the indices: x[i] == x[-i]

Did some incremental improvements and reduced char count.

Mathematica, 87
This is directly based on hammar's post, but hopefully it is distinct enough to merit posting.
<<Combinatorica`

f=Catch[Cases[Characters@#~KSetPartitions~2,{x_,x_}:>Throw[""<>x]];0]&

Test:
f /@ {"ABACBDECDE", "DBEACBCADE", "FFFFFF", "FGG", "ABBA", "AABB", "AABAAB"}

{"ABCDE", 0, "FFF", 0, 0, "AB", "AAB"}

Brachylog, 11 bytes
{;Ẹp}ᵐzcᵛ.∨

Try it online!
Using an unbound output variable as 0 might be cheating, so +1 byte if that's a problem (even though ideally it could just be allowed to fail and we could drop the .∨).
{   }ᵐ         For each character of the input,
 ;Ẹ            pair it with an empty string
   p           in either order.
      z        The zipped pairs
       cᵛ      concatenate to the same thing,
         .     which is output.
          ∨    If that's not possible, leave the output unbound instead of failing.

D
string c(string in,string a=[],string b=[]){
    if(in.length==0)return a==b?a;"0";
    auto r=c(in[1..$],a~in[0],b);
    return r=="0"?c(in[1..$],a,b~in[0]):r;
}
void main(){writeln(c(readline));}

using depth first recursive search
I can make it faster with a int i = min(a.length,b.length);if(a[0..i]!=b[0..i])return "0"; guard clause

On IDEONE, I failed trying to start the program with void main(){writeln(c("ABCADABCAD"));} - just a different version of D, my fault, something else? What's about "ABCABCA"?

you'll need to import std.stdio; for the IO

Ruby, 89 characters
s=->a,x,y{a=="\n"?x==y ?x:?0:[s[b=a[1..-1],x+c=a[0],y],s[b,x,y+c]].max}
$><<s[gets,'','']

This code implements a plain recursive search algorithm. The input must be given on STDIN.

Perl, 68 chars
/^((.+)(?{local($x,$,)=($,,$x.$^N)}))+$(?(?{$o=$,eq$x&&$,})|x)/?$o:0

The input string assumed to be in the $_ variable, the output is the value of the expression.  Trailing newlines in input are ignored.  You can run this from the command line like this:
perl -lne 'print /^((.+)(?{local($x,$,)=($,,$x.$^N)}))+$(?(?{$o=$,eq$x&&$,})|x)/?$o:0'

This code makes use of Perl's regexp engine (and specifically its embedded code execution feature) to do the backtracking.  Basically, it matches the input string against the regexp ^((.+))+$, keeping track of the odd- and even-numbered submatches in $x and $,, and rejecting the match at the end if the two aren't equal.

Does this have the correct result for AABAAB?

Yes it does.  (In fact, AABAAB is an easy case for this solution, since the outer group only needs to match twice.  It took me much longer to get it to handle AABB right.)

Python, 168 characters
def f(s):
 c=s[0]
 d=i=r=0
 if s==c+c:r=c
 while i+1 and i<=len(s)/2 and not r:
  if i:d=f(s[1:i]+s[i+1:])
  if d:r=c+d
  i=s.find(c,i+1)
 return r
print f(raw_input())

05AB1E, 11 bytes
.œ€ιJ.ΔË}θ<

Try it online or verify all test cases.
If a more flexible output would have been allowed which outputs -1 instead of 0, and ["ABCDE","ABCDE"] instead of "ABCDE", it could have been 8 bytes instead:
.œ€ιJ.ΔË

Try it online or verify all test cases.
Explanation:
.œ         # Get all partitions of the (implicit) input-string
           #  i.e. "AABB" → [["A","A","B","B"],["A","A","BB"],["A","AB","B"],["A","ABB"],
           #   ["AA","B","B"],["AA","BB"],["AAB","B"],["AABB"]]
  €ι       # Uninterleave each partition
           #  → [[["A","B"],["A","B"]],[["A","BB"],["A"]],[["A","B"],["AB"]],[["A"],["ABB"]],
           #   [["AA","B"],["B"]],[["AA"],["BB"]],[["AAB"],["B"]],[["AABB"],[]]]
    J      # Join the inner lists together to a single string
           #  → [["AB","AB"],["ABB","A"],["AB","AB"],["A","ABB"],
           #   ["AAB","B"],["AA","BB"],["AAB","B"],["AABB",""]]
     .Δ    # Find the first result for which:
           # (will result in -1 if none are valid)
       Ë   #  Both strings are equal, thus a twin
      }θ   # Afterwards, only leave the last value (the single string if we've found a
           # twin; or 1 if it resulted in -1)
           #  i.e. ["AB","AB"] → "AB"
           #  i.e. -1 → 1
        <  # And decrease by 1 (no-op if it was a string with just uppercase letters)
           #  i.e. "AB" → "AB"
           #  i.e. 1 → 0
           # (after which the result is output implicitly)

JavaScript (Node.js), 54 bytes
g=([c,...x],p,q)=>c?g(x,[p]+c,q)||g(x,[q]+c,p):p==q&&p

Try it online!
Try each split

Scala, 431 bytes
431 bytes, it can be golfed much more.

Golfed version. Try it online!
def g(n:Int)={
def l(n:Int,r:Int):ArrayBuffer[List[Int]]=if(r==0)ArrayBuffer(List())else if(r==n)ArrayBuffer((0 until n).toList)else l(n-1,r-1).map(n-1::_)++l(n-1,r)
l(n,n/2)}
def u(s:String)={
val l=s.length
if(l%2!=0)"0"
else{
val c=g(l)
var r="0"
var m=0
for(b<-c){
val i=b.toSet
val a=(0 until l).filterNot(i)
val h=i.toList.sorted.map(s.charAt)
val d=a.sorted.map(s.charAt)
if(h==d&&h.length>m){
m=h.length
r=h.mkString
}}
r}}

Ungolfed version. Try it online!
import scala.collection.mutable.ArrayBuffer

object Main {

  def getCombinations(n: Int): ArrayBuffer[List[Int]] = {
    def loop(n: Int, r: Int): ArrayBuffer[List[Int]] = {
      if (r == 0) ArrayBuffer(List())
      else if (r == n) ArrayBuffer((0 until n).toList)
      else loop(n - 1, r - 1).map(n - 1 :: _) ++ loop(n - 1, r)
    }

    loop(n, n / 2)
  }

  def untwin(s: String): String = {
    val length = s.length
    if (length % 2 != 0) {
      return "0"
    }

    val combinations = getCombinations(length)

    var result: String = "0"
    var maxLen = 0
    for (comb <- combinations) {
      val i = comb.toSet
      val rest = (0 until length).filterNot(i)
      val firstHalf = i.toList.sorted.map(s.charAt)
      val secondHalf = rest.sorted.map(s.charAt)
      if (firstHalf == secondHalf && firstHalf.length > maxLen) {
        maxLen = firstHalf.length
        result = firstHalf.mkString
      }
    }

    result
  }

  def main(args: Array[String]): Unit = {
    println(untwin("ABACBDECDE")) // "ABCDE"
    println(untwin("DBEACBCADE")) // "0"
    println(untwin("FFFFFF")) // "FFF"
    println(untwin("FFGGG")) // "0"
    println(untwin("ABBA")) // "0"
    println(untwin("AABB")) // "AB"
    println(untwin("AABAAB")) // "AAB"
  }
}

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Display Peter's keyboard pattern
Assume an simple keyboard with this layout:
1 2 3 4 5 6 7 8 9 0
A B C D E F G H I J
K L M N O P Q R S T
U V W X Y Z . , ? !

Peter's keyboard pattern can be generated by starting at the top left of the keyboard, and displays the first three characters and a newline. It shifts over one character and displays the second, third, and fourth key. Once it reaches the end of a row it continues at the end of the next row and goes backwards, until it reaches the start of that row and then goes forward on the next row, and so on until it reaches the beginning of the last row.
This is Peter's keyboard pattern:
123
234
345
456
567
678
789
890
90J
0JI
JIH
IHG
HGF
GFE
FED
EDC
DCB
CBA
BAK
AKL
KLM
LMN
MNO
NOP
OPQ
PQR
QRS
RST
ST!
T!?
!?,
?,.
,.Z
.ZY
ZYX
YXW
XWV
WVU

Write a program which accepts no input and displays Peter's keyboard pattern. The program must be smaller than 152 bytes, i.e. the size of the string it outputs.
This is code golf, so the shortest solution wins.

Even in Golfscript I'm struggling to come up with a shorter way of generating the 40-character base string.

@PeterTaylor I was expecting somebody to use some sort of list comprehension, like [1..9 0 J..A K..T ! ? , . Z..U].

You can use echo {1..9} "0" {J..A} {K..T} '!?,.' {Z..U}|sed 's/ //g' in bash, but need already 13 chars to append a sed-command, to remove blanks. This makes 57 chars, and no triple has been build so far. With sed's hold-command, it should be possible, but in 6 chars, to beat the perl-solution?

The 152 byte limit seems unnecessary--hardcoding the output with no compression whatsoever is bad golfing anyways. It could also potentially bar languages such as brainf**k, where large programs are almost always the occurance but there still could be some clever golfing going on.

Perl, 63 chars
say for"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"=~/(?=(...))/g

This solution uses the say function (available since Perl 5.10.0 with the -E switch, or with use 5.010).  Without it, the best I can do is 67 chars (and an extra newline at the end of the output):
print"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"=~/(?=(...))/g,$,=$/

Earlier 65-char solution:
s//1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU/;s!(?=(...))!say$1!eg

Replacing say$1 with print$1.$/ lets the code run on older perls, at the cost of 5 extra characters.

you beat me for few characters. +1.

Go for the 63-char solution directly. meta discussion

J, 66 62 45 characters
Turns out I was being too clever by half.
3]\'1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'

is all I needed all along.
Previously:
_2}.|:>(];1&|.;2&|.)'1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'

and:
38 3$($:@}.,~3$])^:(3<#)'1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'

APL, 43 characters
⍪3,/(1⌽⎕D),(⌽10↑⎕A),(10↑10⌽⎕A),'!?,.',6↑⌽⎕A

This works on Dyalog APL. I managed to save a couple characters by generating the output string (everything after ⊃). I'll write up an explanation when I get some time!
Here's how the output looks:
      ⍪3,/(1⌽⎕D),(⌽10↑⎕A),(10↑10⌽⎕A),'!?,.',6↑⌽⎕A
 123
 234
 345
 456
 567
 678
 789
 890
 90J
 0JI
 JIH
 IHG
 HGF
 GFE
 FED
 EDC
 DCB
 CBA
 BAK
 AKL
 KLM
 LMN
 MNO
 NOP
 OPQ
 PQR
 QRS
 RST
 ST!
 T!?
 !?,
 ?,.
 ,.Z
 .ZY
 ZYX
 YXW
 XWV
 WVU

Explanation, from right to left:

First, we construct the string seen in all of the other entries:

6↑⌽⎕A: ⎕A gives us a string of the uppercase alphabet, from A to Z. We then reverse it (⌽) and take (↑) the first 6 characters of it, giving us 'ZYXWVU'. (In retrospect, this approach doesn't end up saving any characters, but I'll leave it because it fits in better.)
'!?,.',: We concatenate (,) the string '!?,.' with the previous result.
(10↑10⌽⎕A),: We take the first 10 characters (10↑) of the alphabet, which is first rotated ten times (10⌽), and concatenate this with the previous result. As an example of rotation, 5⌽'abcdef' (the string 'abcdef' rotated 5 times) gives us 'cdefab'.
(⌽10↑⎕A),: Take the first 10 characters of the alphabet and reverse them, and concatenate this with the previous string.
(1⌽⎕D),: ⎕D gives us the digits as a string, from 0 to 9, inclusive. We then rotate ('⌽') this string by 1, yielding '1234567890'. As before, we concatenate this with the previous result.

Now that we have our string built (which saved us 3 characters from the APL representation, due to surrounding quotes), we do some magic to build our final output:

3,/: We take the string, in groups of three characters, and concatenate them.
To finish it off, we use ⍪ to ravel our vector of strings (really a vector of character vectors) along the first dimension. This has the effect of changing its shape from 38 to 38 1 (a 38x1 matrix).

Scala 70 chars:
"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU".sliding(3,1).mkString("\n")

R (75 characters)
embed(strsplit("1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU","")[[1]],3)[,3:1]

What does this do?

strsplit splits a string into substrings, in this case individual characters
embed is a really useful function that turns a vector into an array of overlapping elements
The rest is just indexing and sorting columns in the right order.

This produces and prints an array of characters:
> embed(strsplit("1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU","")[[1]],3)[,3:1]
      [,1] [,2] [,3]
 [1,] "1"  "2"  "3"
 [2,] "2"  "3"  "4"
 [3,] "3"  "4"  "5"
 [4,] "4"  "5"  "6"
 [5,] "5"  "6"  "7"
 [6,] "6"  "7"  "8"
 [7,] "7"  "8"  "9"
 [8,] "8"  "9"  "0"
 [9,] "9"  "0"  "J"
[10,] "0"  "J"  "I"
[11,] "J"  "I"  "H"
[12,] "I"  "H"  "G"
[13,] "H"  "G"  "F"
[14,] "G"  "F"  "E"
[15,] "F"  "E"  "D"
[16,] "E"  "D"  "C"
[17,] "D"  "C"  "B"
[18,] "C"  "B"  "A"
[19,] "B"  "A"  "K"
[20,] "A"  "K"  "L"
[21,] "K"  "L"  "M"
[22,] "L"  "M"  "N"
[23,] "M"  "N"  "O"
[24,] "N"  "O"  "P"
[25,] "O"  "P"  "Q"
[26,] "P"  "Q"  "R"
[27,] "Q"  "R"  "S"
[28,] "R"  "S"  "T"
[29,] "S"  "T"  "!"
[30,] "T"  "!"  "?"
[31,] "!"  "?"  ","
[32,] "?"  ","  "."
[33,] ","  "."  "Z"
[34,] "."  "Z"  "Y"
[35,] "Z"  "Y"  "X"
[36,] "Y"  "X"  "W"
[37,] "X"  "W"  "V"
[38,] "W"  "V"  "U"

+1 embed is very useful function indeed!

Mathematica, 73
I independently arrived at the same method as everyone else:
Grid@Partition[Characters@"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU",3,1]

C, 98 104 characters
Since no one else has done so yet, I thought I would try actually generating the string on the fly, using some kind of run-length encoding for ascending and descending runs.
EDIT: After a number of iterations, here's finally a "clever" solution that ties with the shortest "dumb" solution in C at 98 characters:
char*s="0º.ÿK»Jº ü=ÿ*ø[×",a[99],*p=a,i;main(j){for(;i-=i<8?j=*s++,*s++:8;puts(p++))p[2]=j+=i%4-1;}

The code requires an 8-bit Latin-1 encoding (ISO-8859-1 or Windows-1252), which should work fine on all commonly used platforms, but saving the source with some less popular 8-bit code page, or UTF-8 will not work.
The data string was created by the following piece of emacs lisp:
(require 'cl)
(apply 'concat
  (let ((last-remainder 0))
    (loop for (begin count step twiddle)
          in '((?1 9 +1 4) (?0 1 +2 4) (?J 10 -1 4) (?K 10 +1 0)
               (?! 1 +1 4) (?? 1 +2 4) (?, 2 +2 4) (?Z 6 -1 8))
          append (prog1 (list (char-to-string (- begin step))
                              (char-to-string
                               (logand 255 (- last-remainder
                                              (+ (* 8 (- count 1)) (+ step 1)
                                                 twiddle)))))
                   (setq last-remainder (+ (logand twiddle 7) step 1))))))

The "twiddle" bit is used to avoid unprintable ASCII control characters in the encoded data string, and to ensure that i==0 only at the end of the output.
C, 98 characters
However, even in C you can get a short program by simply printing consecutive triplets from the original string:
main(){char s[]="12,34567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU",*p=s+2;for(;*p=p[1];puts(p-3))*++p=0;}

Groovy, 73
(0..37).each{println"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"[it..it+2]}

All the clever stuff I tried turned out to be longer than doing it the dumb way.

Python, 73
for i in range(38):print"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"[i:i+3]

Ruby 69 65 62
Based on Groovy example
38.times{|i|p"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"[i,2]}

I think the convention here in the past for multiple answers in different languages has been to post one answer for each language.

Haskell, 80
mapM_(putStrLn.take 3.(`drop`"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"))[0..37]

Kotlin, 140 71 bytes
"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU".windowed(3).map{println(it)}

Try it online!
I just realized it's easier to use the string itself instead of generating it using ranges.

Javascript, 103
for(a='1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU';a.length>2;a=a.substring(1))console.log(a.substr(0,3))

An anonymous user suggested reducing this to 93 chars as for(a='1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU';a[3];a=a.slice(1))console.log(a.slice(0,3))

Haskell, 94
main=putStr.unlines.take 38$take 3`map`iterate tail"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"

Perl, 73 characters:
print substr('1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU',$_,3),$/for 0..37

Perl, 66 characters:
say substr"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU",$_,3for 0..37

when called by:
perl -E 'say substr"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU",$_,3for 0..37'

D 124 chars
import std.stdio;void main(){enum s="1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU";
foreach(i;3..s.length){writeln(s[i-3..i)]);}}

JavaScript, 83 chars
for(i=0;i<38;)console.log('1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'.substr(i++,3))

Decided to see if I could beat stephencarmody's solution.  This is what I came up with.

Smalltalk 102 99
1to:38 do:[:i|x:='1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'copyFrom:i to:i+2.Transcript cr show:x]

I don't know Smalltalk very well so it's a little bit strange to me. It's compiles with gst others are not tested.

First trick: remove the space between 38 and do: -> 98 - second trick to remove another space, loop from 3to:40 and copyFrom:i-2to:i ->97 - third trick, don't use a variable x:=... show:x, just show:('...'copyFrom:i-2to:i) directly, that's -4 chars + 2 parenthesis ->95

Prolog, 131
This is probably why you never see Prolog entries.
The newline is required (actually, any whitespace will do but there has to be whitespace).
z(S,L):-append(_,X,L),append(S,_,X),length(S,3).
:-forall(z(X,"1234567890JIHFEDCBAKLMNOPQRST!?,.ZYXWVU"),writef("%s\n",[X])),halt.

Q (66 63 chars)
(((!)38),'3)sublist\:"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"

///, 151 bytes
123
234
345
456
567
678
789
890
90J
0JI
JIH
IHG
HGF
GFE
FED
EDC
DCB
CBA
BAK
AKL
KLM
LMN
MNO
NOP
OPQ
PQR
QRS
RST
ST!
T!?
!?,
?,.
,.Z
.ZY
ZYX
YXW
XWV
WVU

Try it online!
Can't golf it more? This is, in a sense, <152 bytes.

This is not a serious contender by our rules. You make no effort to do better than the minimum score.

I can't, that's why I posted it as-is. If you think you could do better, you can try. I don't know of any shorter solution, and, in fact, I did put some effort in, but realized that this isn't ever going to be further golfed down.

I'm not convinced that this can be golfed at all in ///, but the spec says the program must be shorter than [...] the string it outputs, which isn't the case here.

@Dennis No, it says the program must be smaller than 152 bytes (151 < 152). I think it's an error, or I read the post differently, but i.e. does not override the meaning of something, it just helps you to better understand it, in my sense. Also, I didn't include a trailing newline, maybe that's why this is 151 bytes. And yes, I read that section.

Jelly, 41 40 bytes
ØAḣ⁵Ṛ
ØDṫ2;0;¢;“KLMNOPQRST!?,.ZYXWVU”ṡ3Y

Try it online!
Might (still) be golfable...

Brachylog, 26 bytes
Ị↺,Ạ,".,?!"ụḍ₄{i↔ⁱ⁾}ᶠcs₃ẉ⊥

Try it online!
Essentially a translation of my Jelly answer. A full program which prints the desired output with a trailing newline.
Ị                             "0123456789"
 ↺                            rotated once to the left
  ,                           concatenated with
   Ạ                          the alphabet (lowercase)
    ,".,?!"                   concatenated with ".,?!",
           ụ                  uppercased,
            ḍ₄                sliced into quarters.
                     c        Concatenate
              {    }ᶠ         every possible result from
               i              taking a slice with its 0-index
                ↔             and reversing it
                 ⁱ⁾           a number of times equal to the index.
                        ẉ     Print with a newline
                      s₃      a substring of length 3 from the concatenation,
                         ⊥    then try again with a different substring.

If a trailing newline is unacceptable:
Brachylog, 27 bytes
Ị↺,Ạ,".,?!"ụḍ₄{i↔ⁱ⁾}ᶠcs₃ᶠ~ṇ

Try it online!
Outputs as a function.

05AB1E, 24 bytes
žhÀAu".,?!"«Tô2Å€R}J«ü3»

Try it online.
Minor alternative:
Au".,?!"«TôžhÀšεNFR]Jü3»

Try it online.
Explanation:
žh                       # Push builtin "0123456789"
  À                      # Rotate it once to the left: "1234567890"
   Au                    # Push the uppercase alphabet
     ".,?!"«             # Append ".,?!" to it
            Tô           # Split it into parts of size 10:
                         #  ["ABCDEFGHIJ","KLMNOPQRST","UVWXYZ.,?!"]
              2Å€ }      # For every 2nd item (0-based index modulo 2 == 0):
                 R       #  Reverse it
                         #   ["JIHGFEDCBA","KLMNOPQRST","!?,.ZYXWVU"]
                   J     # Join the list together to a single string again:
                         #  "JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"
                    «    # Merge it to the digits:
                         #  "1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"
                     ü3  # Create overlapping triplets
                       » # Join the list by newlines
                         # (after which it is output implicitly with trailing newline)

Au".,?!"«Tô              # Same as above: ["ABCDEFGHIJ","KLMNOPQRST","UVWXYZ.,?!"]
           žhÀ           # Same as above: "1234567890"
              š          # Prepend it to the list:
                         #  ["1234567890","ABCDEFGHIJ","KLMNOPQRST","UVWXYZ.,?!"]
               ε         # Map each string to:
                NF       #  Loop the 0-based map-index amount of times:
                  R      #   Reverse the string every iteration
                   ]     # Close both the loop and map
                    J    # Join the list together to a single string again:
                         #  "1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"
                     ü3» # Same as above
                         # (after which it is output implicitly with trailing newline)

Jelly, 24 23 bytes
ØDṙ1;ØA;“.,?!”s⁵UÐeFṡ3Y

Try it online!
Generates the keyboard top to bottom left to right, then boustrophedonizes it afterwards.
ØD                         "0123456789"
  ṙ1                       rotated once to the left
    ;                      concatenated with
     ØA                    the uppercase alphabet
       ;“.,?!”             concatenated with ".,?!".
              s            Chop it into slices of length
               ⁵           10,
                U          (vectorized) reverse
                 Ðe        the slices at even 1-indices,
                   F       smash the slices back together,
                    ṡ3     take every contiguous sublist of length 3,
                      Y    and join on newlines.

Q, 63
{(x;3)sublist"1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU"}'[(!)38]

x86-16 machine code, PC DOS, 64 bytes
Binary:
00000000: b409 bb1b 01ba 1801 bf0a 24b1 2687 3fcd  ..........$.&.?.
00000010: 2187 3f42 43e2 f6c3 3132 3334 3536 3738  !.?BC...12345678
00000020: 3930 4a49 4847 4645 4443 4241 4b4c 4d4e  90JIHGFEDCBAKLMN
00000030: 4f50 5152 5354 213f 2c2e 5a59 5857 5655  OPQRST!?,.ZYXWVU

Listing:
BB 011B     MOV  BX, OFFSET KB+3        ; pointer to end of 3 char substring
BA 0118     MOV  DX, OFFSET KB          ; pointer to beginning of 3 char substring
BF 240A     MOV  DI, 240AH              ; string '$' + 0AH
B1 26       MOV  CL, 38                 ; number of lines
B4 09       MOV  AH, 9                  ; DOS API output string function
        CLOOP:
87 3F       XCHG DI, WORD PTR[BX]       ; swap string term and LF char after 3 chars
CD 21       INT  21H                    ; write substring to console
87 3F       XCHG DI, WORD PTR[BX]       ; swap back
42          INC  DX                     ; increment string start pointer
43          INC  BX                     ; increment string end pointer
E2 F6       LOOP CLOOP                  ; loop until 38 lines
C3          RET                         ; return to DOS
        KB:
            DB  '1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'

It's a bit of a naïve approach, but still fits well below the spec size (and is a nice power of 2).  Loops through the string and swaps the relative 4th and 5th character with a LF followed by a string terminator and then outputs it.
Standalone DOS executable COM program.  Output:
Head:

Tail:

Japt -R, 27 bytes
;9õ pUB".,?!" ¬ò10 ËzEÑÃ¬ã3

Test it
;9õ pUB".,?!" ¬ò10 ËzEÑÃ¬ã3
 9õ                             :Range [1,9]
    p                           :Push
     U                          :  0
;     B                         :  Uppercase alphabet
       ".,?!"                   :  String literal
              ¬                 :Join
               ò10              :Partitions of length 10
                   Ë            :Map each string a 0-based index E
                    z           :  Rotate clockwise 90 degrees
                     EÑ         :  E*2 times
                       Ã        :End map
                        ¬       :Join
                         ã3     :Substrings of length 3
                                :Implicit output, joined with newlines

PowerShell 6+, 62 bytes
0..37|%{'1234567890JIHGFEDCBAKLMNOPQRST!?,.ZYXWVU'|% s*g $_ 3}

Try it online!
where s*g is the shorcut for the Substring method.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/