share
Code GolfPrint a Christmas Tree
[+30] [87] Averroes
[2011-12-05 14:44:27]
[ code-golf ascii-art kolmogorov-complexity ]
[ https://codegolf.stackexchange.com/questions/4114/print-a-christmas-tree ]

The Challenge

Print a nice Christmas tree with it's own star at the top using the shortest code possible. The tree star is an asterisk (*) and the tree body is made out of 0 The tree must be 10 rows high. Every row should be properly indented in the way that the previous row are centered over the next one. Any given row must have 2 more 0s than the previous, except for the first one that is the star and the second, which has only one 0. The result is something like this:

          *
          0
         000
        00000
       0000000
      000000000
     00000000000
    0000000000000
   000000000000000
  00000000000000000

Tie break for resizable height trees without software changes (except changing height parameter)

Please, paste the resulting tree of your code too!


Leaderboard

var QUESTION_ID=4114,OVERRIDE_USER=73772;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

(3) Not exactly a duplicate but there's this one on SO: Code Golf Christmas Edition: How to print out a Christmas tree of height N - Hasturkun
[+58] [2011-12-05 20:38:39] Ilmari Karonen

I know this doesn't comply with the spec, but I thought I'd try to add some diversity to the trees here by imitating this classic ASCII art Christmas scene by Joan G. Stark [1].

I didn't try to reproduce the whole picture — that would've been a bit too much — but just the tree, for which I present this 138-byte Perl program:

$_=join$/,qw'11| 8\2_2/ 9(\o/) 5---2/1\2--- 10>*<',map(11-$_.A.AA x$_,2..11),'9\|H|/';s/\d+/$"x$&/eg,s/A/substr">>>@*O<<<",rand 9,1/eg,say

And, of course, here's a sample of the output:

           |
        \  _  /
         (\o/)
     ---  / \  ---
          >*<
         >O><@
        <><<>><
       @><><>@<<
      @<O><*@*>>O
     OO@@*O<<<*<OO
    ><<>@><<>@<><><
   >><O<>>><@*>>><<O
  *<>*<><<>@><O*>><*<
 O><><<@<*>><O*@>O><>*
O<><<><@O>>*O*OO<><<>O>
         \|H|/

Try it online! [2]

The code uses the Perl 5.10+ say feature, and so needs to be run with the -M5.010 (or -E) command line switch. (Actually, just replacing the say at the end with print would avoid that, at the cost of two more bytes and the loss of the newline after the last line of output.)

Note that the bulk of the tree is randomly generated, so the placement of the ornaments will vary between runs. The angel, the stand and the top row of the tree are fixed, though.


To keep this popular answer from being summarily deleted under a policy instituted after it was posted [3], here's a token spec-compliant solution as well (45 bytes, also Perl 5):

$_=$"x10 ."*";say,s/ 0/00/,s/\*?$/0/ while/ /

Try it online! [4]

Like the program above, this one also needs to be run on Perl 5.10+ with the -M5.010 switch to enable the say feature. Obviously (this being a [5] challenge) it produces the exact same boring output as all the other compliant entries, which I won't bother repeating here. (It's also trivially resizable by changing the number 10 to any other other value.)

[1] https://asciiart.website/joan/www.geocities.com/SoHo/7373/xmas.html#greetings
[2] https://tio.run/##HcrdCoIwGADQVxky8qdtn99ASLLR7rqJXmAwDCWMcuaMDHz2VnR1bs7QjrciBGp3V9f1FNjjFSMuZGOklUDKxDhIScE5l4BG/iSYq6yK2b0eEkROrdBCazJTy6QQiCmLS7McFoi3HkyzBhrNdAXthXnQ4J9nP42RUmqfnaqqithY9w0pGf5H/Q7h44apc70P/FiIHPMv
[3] https://codegolf.meta.stackexchange.com/a/7990
[4] https://tio.run/##K0gtyjH9/18l3lZFqcLQQEFPSUvJujixUqdYX8FA38BAH8iI0bJX0TfQVyjPyMxJ1VfQ////X35BSWZ@XvF/XV9TPQNDAwA
[5] /questions/tagged/kolmogorov-complexity

(1) Great! Not by the spec but I think the judges special award is for you! :) - Averroes
(6) this kicks the specs' proverbial behind, +2 if I could. - Kris
(3) Sorry, but per the rules, answers that don't meet the spec must be deleted. - mbomb007
I'm deleting this post in compliance with our policy about answers not meeting the challenge specification. - Dennis
(1) Could you please move the valid answer to the top and add a header? - Dennis
1
[+17] [2011-12-07 15:38:03] Ventero [ACCEPTED]

Golfscript, 27 characters

" "9*"*"9,{n\.4$>\.+)"0"*}%

The resulting tree looks like this:

         *
         0
        000
       00000
      0000000
     000000000
    00000000000
   0000000000000
  000000000000000
 00000000000000000

A version which uses the height parameter only once is one character longer:

9." "*"*"@,{n\.4$>\.+)"0"*}%

Reading the height from stdin (with input "10" to generate the example tree) takes the same amount of characters (28):

~,)" "*"*"@{n\.4$>\.+)"0"*}%

2
[+13] [2011-12-05 20:26:15] Peter Taylor

GolfScript (33 chars)

Fixed-height version:

;8:^' '*.'*'+\'0'+^{.(;'00'+}*]n*

Or for exactly the same length

;8:^' '*.'*'+n@'0'+^{.n\(;'00'+}*

The tree looks remarkably similar to everyone else's:

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

Version which takes height from stdin:

~((:^' '*.'*'+\'0'+^{.(;'00'+}*]n*

The start of the previous line is one of the better smilies I've made in a "useful" GolfScript program.


3
[+10] [2011-12-06 12:17:05] Evan Krall

Shell script, 44 characters

printf %9c\\n \* 0|sed ':x
p;s/ 0/000/;tx
d'

Prints this tree:

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

4
[+9] [2011-12-05 20:18:05] Howard

Ruby, 46 characters

puts" "*8+?*;9.times{|i|puts"%8s0"%(v=?0*i)+v}

In order to change the height you would have to change both 8s and of course also the 9. The output of the program is as follows:

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

Edit: Inexcusably I omitted the output in the first submission.


(1) You forgot to post the output. :) - Ilmari Karonen
5
[+9] [2011-12-06 23:04:12] Ilmari Karonen

Maple, 30 / 37 chars

Inspired by Mr.Wizard's Mathematica entry [1], I present this 30-char Maple 12 command:

<`*`,('cat(0$2*i+1)'$i=0..8)>;

Output:

                              [        *        ]
                              [                 ]
                              [        0        ]
                              [                 ]
                              [       000       ]
                              [                 ]
                              [      00000      ]
                              [                 ]
                              [     0000000     ]
                              [                 ]
                              [    000000000    ]
                              [                 ]
                              [   00000000000   ]
                              [                 ]
                              [  0000000000000  ]
                              [                 ]
                              [ 000000000000000 ]
                              [                 ]
                              [00000000000000000]

I can also get rid of the brackets at the cost of seven more chars:

`*`;for i in$0..8 do;cat(0$2*i+1);od;

Output omitted — it looks just like above, only without the brackets. Unfortunately, I don't know any way to keep Maple from inserting blank lines between the output rows in text mode. It looks better in classic worksheet mode. I guess I could include a screenshot...

screenshot

(The screenshot shows an earlier 44-char version of the command, but I'm too lazy to retake it. The output is still the same.)

Oh, and yes, the size is fully adjustable: just replace the 8 with n-2 for an n-row tree. With the first solution, going above 25 rows (or 10 in the GUI) requires also setting interface(rtablesize = n), though.

(Ps. I thought I'd managed to beat GolfScript [2] with the latest version, but alas... [3])

[1] https://codegolf.stackexchange.com/a/4139/3191
[2] https://codegolf.stackexchange.com/a/4132/3191
[3] https://codegolf.stackexchange.com/a/4185/3191

6
[+8] [2011-12-05 15:19:03] Ilmari Karonen

Perl, 42 chars

say$"x9,"*";say$"x(9-$_),"00"x$_,0for 0..8

Output:

         *
         0
        000
       00000
      0000000
     000000000
    00000000000
   0000000000000
  000000000000000
 00000000000000000

The height of the tree can be changed between 1 and 11 rows by replacing the 8 at the end with values from -1 to 9. Going above 11 rows requires also increasing the two 9s earlier in the code, which control how far from the left side of the screen the tree is indented.


This one have 11 rows :P Minor changes I guess - Averroes
@Averroes: Yeah, I first assumed it was supposed to be 10 rows plus the star, but then I actually counted the rows in the sample output and fixed it. - Ilmari Karonen
7
[+8] [2011-12-05 17:06:19] Armand

Groovy, 65

(p={c,r->println' '*(9-r)+(c*(r*2-1))})'*',1;(1..9).each{p'0',it}

Surprisingly, the tree looks like this:

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

The 'post the tree output' part is for bringing some Christmas spirit to this site :P - Averroes
Also, yours have 11 rows too! - Averroes
I can fix that by adjusting the height parameter(s)! - Armand
8
[+7] [2011-12-06 00:44:20] Kazark

Python 3: 62 characters

print(' '*9+'*',*('\n'+' '*(9-i)+'0'*(i*2+1)for i in range(9)))

Output:

        * 
        0 
       000 
      00000 
     0000000 
    000000000 
   00000000000 
  0000000000000 
 000000000000000
00000000000000000

Note that this essentially beats @Ante's answer by 11 characters, because that answer, when converted to Python 3, uses 73 characters.

Change each 9 to another value for a different height.


(3) I think you can also lose the space before for. - badp
@badp Thanks—changed from 63 to 62! - Kazark
9
[+7] [2011-12-06 06:00:03] Jaykul

PowerShell, 41

" "*8+"*";0..8|%{" "*(8-$_)+"0"+"0"*$_*2}

Unsurprisingly, outputs the same tree as everyone else's :-p

If you parametrize that 8, it will yield up to the size of your console, in, say, 48 characters:

" "*($w=8)+"*";0..$w|%{" "*($w-$_)+"0"+"0"*$_*2}

Or, as a full-blown script which takes an argument, 53 characters:

param($w)" "*$w+"*";0..$w|%{" "*($w-$_)+"0"+"0"*$_*2}

Called, it looks like:

PS>: Get-Tree.ps1 8
        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

10
[+6] [2011-12-06 07:37:57] Patrick

Python, 59

print' '*9+'*'
for i in range(9):print' '*(9-i)+'0'*(i*2+1)

Nice work—this demonstrates that though the answer by @Ante gets longer in Python 3, my Python 3 answer is shorter in Python 2 (print not a function). - Kazark
11
[+6] [2011-12-06 17:14:45] Paul Butcher

Prolog: 183 or 186

r(0,_,L,L).
r(N,C,L,[C|T]):-N>0,M is N-1,r(M,C,L,T).
y(S,T,C):-r(T,C,[10],X),r(S,32,X,Y),atom_codes(A,Y),write(A).
x(A,B):-A>0,y(A,B,48),C is A-1,D is B+2,x(C,D).
x(N):-y(N,1,42),x(N,1).

Prints:

         *
         0
        000
       00000
      0000000
     000000000
    00000000000
   0000000000000
  000000000000000
 00000000000000000
false.

Could be squeezed further for certain interpreters (e.g. using tab/1 on SWI)

Invoke with x(N). Where N is the number of rows in the actual tree (excluding star). Giving it a fixed height would bring it down to 183


12
[+6] [2011-12-13 22:50:54] Skizz

C

This is Wade Tandy's C version but modified a little bit:

           ;
          int
         main(
        ){int i
       =-1,j=0,c
      =10;while(j
     ++<c){printf(
    " ");}{;printf(
   "*");}while(++i<c
  ){for(j=-2;++j<c-i;
 )printf(" ");for(j=0;
++j<2*i;){printf("0");}
          ;;;
        printf(
         "\n")
          ;}}

13
[+5] [2011-12-06 01:34:33] Mr.Wizard

Mathematica, 50

MatrixForm@Prepend[Row/@Table[0,{n,9},{2n-1}],"*"]

14
[+5] [2011-12-06 14:53:01] MrMRDubya

PostScript (with parameterised height), 114 characters

/h 9 def/b{{( )=print}repeat}def
h -1 0{dup h eq{dup b(*)=}if dup b h sub neg 2 mul 1 add{(0)=print}repeat()=}for

Output:

         *
         0
        000
       00000
      0000000
     000000000
    00000000000
   0000000000000
  000000000000000
 00000000000000000
0000000000000000000

What, you wanted it to print out?


15
[+5] [2011-12-07 17:26:07] sirchristian

Applesoft BASIC, 143 chars

Since this question reminds me of a homework assignment I had back in high school (when they were teaching on an Apple //e):

1INPUTH:X=(H*2)-2:C=(X/2):S$="*":O=0:GOSUB2:S$="0":FORO=0TOX-2STEP2:GOSUB2:NEXT:END
2FORS=0TOC-(O/2):?" ";:NEXT:FORI=0TOO:?S$;:NEXT:?"":RETURN

I used the JavaScript Applesoft BASIC found here: http://www.calormen.com/applesoft/

OUTPUT:

?10
          *
          0
         000
        00000
       0000000
      000000000
     00000000000
    0000000000000
   000000000000000
  00000000000000000

16
[+5] [2011-12-08 12:57:29] Rob Fox

Prolog: 127 characters

p:-write('        *'),h(1).
h(L):-(L<10,nl,w(L,-8),h(L+1));!.
w(L,N):-(N<9,N<L,(L>abs(N)->write('0');write(' ')),w(L,N+1));!.

Output:

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000
true 

Used Prolog because I was not able to beat the Groovy record without looking at his code :(.


17
[+4] [2011-12-05 21:52:19] Ante

Python, 70 characters

Not so short, but recursive solution :-)

def a(s):
 print s
 if s<"0":a(s[1:]+"00")
print" "*8+"*"
a(" "*8+"0")

Change 8's to set height.


18
[+4] [2011-12-06 07:56:49] Joshua

Javascript, 119 characters

Outputs to firebug console

i=h=9;a=new Array(h);a[0]=a.join(' ');b=a.join('000');a[0]+='*';while(i)a[i--]=b.substr(i,h+i);console.log(a.join('\n'))


        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

(2) This is 120 characters actually. - Rob Fox
19
[+4] [2011-12-06 14:10:27] Graham Christensen

PHP, 106 characters

7 fewer than the previous:

<?php echo str_pad(' ',9)."*\n";for($i=0;$i<9;$i++){echo str_pad("",9-$i).str_pad("",($i*2)+1,"0")."\n";}

(2) enable short tags and save yourself 3 chars, or use the <?= and save another 5 from the "echo ". - Brombomb
I know I'm 8 months late, but codegolf.stackexchange.com/a/6783/4967 :) - Leigh
20
[+4] [2011-12-07 00:45:29] Weston C

JavaScript (Rhino: 108, Node: 114, Webkit Dev Console: 119, jQuery Plugin: 132)


Rhino is the shortest (at 108 characters) because (a) its print function has a short name and (b) it'll let you assign built-in functions into a shorter variable name. So:

h=10,p=print,m='0',a=Array(h-1),s=a.join(' ');p(s+'*\n'+s+m);while(h-->2){m+='00';a.pop();p(a.join(' ')+m);}


Node.js comes in a close second (at 114 chars) because its print function console.log has a longer name, but it'll let us assign that to a short variable as well:

h=10,p=console.log,m='0',a=Array(h-1),s=a.join(' ');p(s+'*\n'+s+m);while(h-->2){m+='00';a.pop();p(a.join(' ')+m);}


However, the Webkit Dev Console (and probably Firebug, too) thinks p=console.log is a bit too sneaky (when you try to call p(), it'll complain at you). So, we have to lengthen things out to 119 characters:

h=10,m='0',a=Array(h-1),s=a.join(' ');with(console){log(s+'*\n'+s+m);while(h-->2){m+='00';a.pop();log(a.join(' ')+m);}}

(Interestingly, with only saves us a character).


Finally... a jQuery plugin (still tweetable at 132 characters!):

$.fn.xms=function(h){var m='0',w=2,l=['*',m];while(w++<h)l.push(m+='00');$(this).css({textAlign:'center'}).html(l.join('\n<br/>'));}

And you can invoke it on the footer of this very page: $('#footer').xms(3)

Of course, it doesn't have to be a plugin... since we'd probably have to use a JavaScript console to add it to a page and invoke it, we could've just done a snippet of jQuery:

h=10,m='0',w=2,l=['*',m];while(w++<h)l.push(m+='00');$('#footer').css({textAlign:'center'}).html(l.join('\n<br/>'));

which weighs in at a more competitive 116 characters -- in fact, it beats out the other dev console implementation. But, then again, using jQuery and/or the browser's layout engine might be considered cheating. :)


21
[+4] [2012-06-21 17:37:21] JoeFish

C, 67

I know this is long over, but it's my first attempt at code golf, and I think I've got a pretty nice C solution.

Interestingly, I came up with this independently of @Patrick's very similar solution.

And yes, I won't win any ties with my hardcoded values ;) I'm quite pleased, anyway.

i;main(){for(;i<10;++i)printf("%*s%0*c\n",i?9-i:8,"",i*2,i?32:42);}
        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000
Press any key to continue . . .

22
[+4] [2012-07-25 03:13:02] Kevin Traver

LOLCODE, 527 bytes

CAN HAS STDIO?
HAI 1.2
IM IN YR LOOP UPPIN YR VAR TIL BOTH SAEM VAR AN 8
    VISIBLE " "!
IM OUTTA YR LOOP
VISIBLE "*"
I HAS A SPACES
SPACES R 8
I HAS A ZEROS
ZEROS R 1
IM IN YR LOOP UPPIN YR VAR TIL BOTH SAEM VAR AN 9
    IM IN YR LOOP UPPIN YR VAR2 TIL BOTH SAEM VAR2 AN SPACES
        VISIBLE " "!
    IM OUTTA YR LOOP
    IM IN YR LOOP UPPIN YR VAR2 TIL BOTH SAEM VAR2 AN ZEROS 
        VISIBLE "0"!
    IM OUTTA YR LOOP
    VISIBLE ""
    SPACES R DIFF OF SPACES AN 1
    ZEROS R SUM OF ZEROS AN 2
IM OUTTA YR LOOP
KTHXBYE

Try it online! [1]

Output:

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000
[1] https://tio.run/##nVHBDoIwDL3vK54cPRjhpCczYIRGYIQNIl7VGwn/f8IxGAkhmmgPXdrXvtd2Xd89@udrGCJeIOUKSsckLyzlBP8QMMpBBdoKmZQl6rKcooZX0JQhlDqF4iK3GUNxYjDWkKIwE/Dg7UYKWWvNHQtb0L3HyIpyqJJHQrHpQWV4HHIXlVTMepP3f57obCf63BVs24Kxb54Is61WmhnXa/0nMy22lTl@k1mqPBsuV4spSSATlzD0vi1w11N1PsJTaNBg@zlXnd7CVgzDGw

(1) This is code-golf, so please add the byte count of your submission to the header. - lirtosiast
23
[+4] [2012-07-25 04:44:51] Phan

Oracle

select lpad('*', 11) from dual
union all
select rpad(' ', 10 - level) || rpad(' ', level * 2, '0') from dual
connect by level <= 9;


          *
          0
         000
        00000
       0000000
      000000000
     00000000000
    0000000000000
   000000000000000
  00000000000000000

10 rows selected.

24
[+3] [2011-12-06 06:44:57] Kris

PHP 113

Figured i'd chime in with a php version:

113 chars (adjust $h to change the height, the number of lines includes the star):

$h=10;for($n=0;$n<$h;$n++){$i=$n>0?$n:1;$c=$n<1?"*":"0";echo str_repeat(" ",$h-$i).str_repeat($c,($i*2)-1)."\n";}

I tried to make it short, not readable and we already knew php can't compete on conciseness so this isn't going to win anything, still a fun little puzzle tho.

output is as spec:

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

Hardcoding a litlle bit more, 103 chars, (you can't see the spaces in the first echo inside this comment) $n=0;echo" *\n";for($i=9;$i>0;$i--,print str_repeat(' ',$i).str_repeat('0',$n+9-$i)."\n",$n++); - Lucia
your hardcoded first line would go out of balance if you change the height of the tree tho :-( - Kris
25
[+3] [2011-12-06 09:09:38] Patrick

C, 77

i;main(c){printf("%*c\n",c,42);while(i<c)printf("%*s%0*d\n",c-i,"",i++*2+1,0);}

Before reading the printf spec more carefully, I had this cute little number down to 138 chars:

#define x sprintf(b,
#define y printf(b,
i;main(c){char b[9]="%%%dc\n",*t="%%%ds%%0%dd\n";x b,c);y 42);while(i<c)x t,c-i,i++*2+1),y "",0);}

26
[+3] [2011-12-06 10:24:31] Daniel Schneller

Java, 192 (198 with param)

class V{public static void main(String[]a){int c=10,i=-1,j=0;String s="";while(j++<c)s+=" ";s+="*";while(++i<c){for(j=-2;++j<c-i;)s+=" ";for(j=0;++j<2*i;)s+="0";System.out.println(s);s="";}}}

Prints the requested tree:

        *           
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

For variable height, slightly longer:

class W{public static void main(String[]a){int c=a.length,i=-1,j=0;String s="";while(j++<c)s+=" ";s+="*";while(++i<c){for(j=-2;++j<c-i;)s+=" ";for(j=0;++j<2*i;)s+="0";System.out.println(s);s="";}}}

Length of command line argument list determines height (e. g. java W a a a a a will give height 5).

(This is basically the Java version of Wade Tandy's C solution.)


I know this was posted a while ago :), but here are two things I see: 1. you can use an interface instead of a class in java 8 2. to save two characters, while (++i < c) { -> for (s += "*";++i < c;s = "") {, and remove the s += "*"; and the s = ""; - Reinis Mazeiks
27
[+3] [2011-12-06 16:42:43] Zvezdochet

Scala, 74 bytes

val h=10;println(" "*h+"*");for(i<-0 to h-2)println(" "*(h-i)+"0"*(i*2+1))

h - height of the tree

Output

        *          
        0          
       000         
      00000        
     0000000       
    000000000      
   00000000000     
  0000000000000    
 000000000000000   
00000000000000000  

28
[+3] [2016-12-07 21:18:23] DJMcMayhem

Vim, 18 bytes

17i0<esc>qqYPxr q8@qa*

Try it online [1] in the backwards-compatible V interpreter!

Although this is a very similar approach as my V answer, this one is not non-competing since vim is crazy old. :)

Explanation:

17i0<esc>               " Insert 17 '0's
         qq     q       " Start recording into register 'q'
           YP           " Duplicate this line upwards
             x          " Delete one character
              r         " Replace this character with a space
                 8@q    " Playback macro 'q' 8 times
                    a*  " Append an asterisk
[1] http://v.tryitonline.net/#code=MTdpMBtxcVlQeHIgcThAcWEq&input=

29
[+2] [2011-12-06 10:29:42] litchie

C, 80

i=9,k=10,j;main(F){while(i)putchar(++j<i?32:j<k?48-F*6:(i-=!F,k+=!F,F=j=0,10));}

Initialize k to the tree height, i to k-1. F is first line flag. Given no argument, then F should be 1 upon entry.

A slightly longer(81) version where f is non first line flag:

i=9,k=10,j,f;main(){while(i)putchar(++j<i?32:j<k?42+f*6:(i-=f,k+=f,f=1,j=0,10));}

30
[+2] [2011-12-06 14:38:50] Paul Butcher

Lua: 83, 89 or 97

A fixed-height 10-layer tree can be done in 83

a=string.rep
for i=0,9 do
print(i<1 and a(" ",8).."*" or a(" ",9-i)..a(0,i+i-1))end

Providing a height parameter takes it to 89

h=9
a=string.rep
for i=0,h do
print(i<1 and a(" ",h-1).."*" or a(" ",h-i)..a(0,i+i-1))end

Changing the first line to h=io.read() takes it up to 97, but allows the program to read the height from stdio.

Prints:

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

Note that the value of h is the size of the tree itself, excluding the star.


31
[+2] [2011-12-07 12:48:59] SiZ

Java, 141

class t{public static void main(String a[]){char s[]=new char[21];s[9]='*';for(int i=0; i<10;System.out.println(s),s[9+i]=s[9-i]='0',i++);}}

Using a char array ..


32
[+2] [2012-03-27 22:55:00] r.e.s.

Whitespace, 2155 bytes

Program (replace S,T,L with Space,Tab,Linefeed characters respectively):

SSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSTSTSLTLSSSSSTSTSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTTSSSSLTLSSSSSTSTSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTSTSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTSTSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTSTSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTSTSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTSTSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTSTSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTSTSLTLSSSSSTSSSSSLTLSSSSSTSSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSSSSTTSSSSLTLSSLLL

or download the whitespace-only program text-file christmas_tree.ws [1].

Output:

          *
          0
         000
        00000
       0000000
      000000000
     00000000000
    0000000000000
   000000000000000
  00000000000000000

This program simply outputs the 164 successive characters that make up the ten rows of the tree (averaging just over 13 program characters per output character). No doubt there's a much shorter Whitespace program that uses some logic to generate the blocks of repeated tree characters.

[1] https://sites.google.com/site/res0001/whitespace/programs/christmas_tree.ws

33
[+2] [2012-06-11 21:37:03] Cristian Lupascu

T-SQL, 151 142 bytes

declare @ int
set @=10;with t as(select space(@-1)+'*'z,1 i
union all
select space(@-i)+replicate('0',i*2-1),i+1 from t)
select top(@)z from t

The height of the tree can be adjusted (just change the value of the @h variable)

The query uses a Recursive CTE [1].

Test link: http://sqlfiddle.com/#!3/d41d8/1695 (from the "Run SQL" dropdown button, select "Plaintext Output")

If run from the SQL Management Studio select "Results to Text" and use this query, as SSMS displays the data left aligned:

declare @h int
set @h=10;with t as(select space(@h-1)+'*'as z,1 as i
union all
select space(@h-i)+replicate('0',i*2-1),i+1 from t)
select top(@h)z from t

Sample SQL Server Management Studio output:

z
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
         *
         0
        000
       00000
      0000000
     000000000
    00000000000
   0000000000000
  000000000000000
 00000000000000000

EDIT: Saved 9 chars thanks to BradC!

[1] http://msdn.microsoft.com/en-us/library/ms186243%28v=sql.105%29.aspx

Nice technique with the recursive CTE. You can save a few bytes by using @ as the variable instead of @h, and by dropping the AS column keywords on z and i (although you'll still need it for table t). Also, in SQL 2008 and later you can set the value as part of the declare: declare @ int=10 - BradC
@BradC Wow, thanks! I don' t know how I forgot about that as, but the @ var name - I didn't think that was possible. :) - Cristian Lupascu
34
[+1] [2011-12-06 11:42:50] Tobias Müller

Java, 177 Chars

import java.util.Arrays;class C{public static void main(String[]a){
char[]r=new char[17];r[8]='*';int c=10;while(c-->0){if(c<9)Arrays.fill(r,c,17-c,'0');System.out.println(r);}}}

(Line break after main(...){ only for better readability.)

Uses API method Arrays.fill() to reduce number of while loops.

Prints this tree:

        *        
        0        
       000       
      00000      
     0000000     
    000000000    
   00000000000   
  0000000000000  
 000000000000000 
00000000000000000

35
[+1] [2011-12-06 14:19:20] Averroes

Java, 230 characters

My own take.

class p{public static void main(String[]a){new p().m();}void m(){int h=0;x(20,1,"*");while(h<9)x(20-h,2*h+++1,"0");}void x(int s,int f,String c){for(;s>0;s--)d(" ");while(f-->0)d(c);d("\n");}void d(String s){System.out.print(s);}}

And the output:

                *
                0
               000
              00000
             0000000
            000000000
           00000000000
          0000000000000
         000000000000000
        00000000000000000

The code indented:

class p {
public static void main(String[] a) {
    new p().m();
}

void m() {
    int h = 0;
    x(20, 1, "*");
    while (h < 9)
        x(20 - h, 2 * h++ + 1, "0");
}

void x(int s, int f, String c) {
    for (; s > 0; s--)
        d(" ");
    while (f-- > 0)
        d(c);
    d("\n");
}

void d(String s) {
    System.out.print(s);
}
}

Adding parameters for height should take only a few more characters, but I am very far way of winning :P


36
[+1] [2011-12-06 14:30:19] stusmith

Haskell, 83 chars

r=replicate
main=mapM_ putStrLn$(r 8' '++"*"):map(\x->r(9-x)' '++r(x*2-1)'0')[1..9]

...not as short as I thought it might be.


37
[+1] [2011-12-06 15:05:20] Jochem

Java, 147 chars (or 153)

class V{public static void main(String[]a){int c=10,i=-1,j;while(++i<c){for(j=0;++j<c+i;)System.out.print(j>c+i-2?i<1?"*\n":"\n":j<c-i?" ":"0");}}}

I based this on Daniel Schneller's solution, although I changed a lot. In line with Daniels solution, this one can be parameterized as well, where the number of command line parameters represents the height of the tree:

class V{public static void main(String[]a){int c=a.length,i=-1,j;while(++i<c){for(j=0;++j<c+i;)System.out.print(j>c+i-2?i<1?"*\n":"\n":j<c-i?" ":"0");}}}

Output (how surprising :):

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

38
[+1] [2011-12-06 21:35:26] Weston C

PHP, 136 Characters


        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000


;)


(1) Now make the size adjustable. :) - Ilmari Karonen
Well, I can't make this size adjustable, but I could write meta-programs which can generate PHP programs like these of arbitrary size ;). - Weston C
39
[+1] [2011-12-06 22:51:24] ICR

C#, 181 Characters

using System;
class T{static void Main(string[]a){
int h=int.Parse(a[0])-2,i=0;
Console.WriteLine("*".PadLeft(h+1));
while(i<=h)
Console.WriteLine(new string('O',i++*2+1).PadLeft(h+i));
}}

Output:

        *
        O
       OOO
      OOOOO
     OOOOOOO
    OOOOOOOOO
   OOOOOOOOOOO
  OOOOOOOOOOOOO
 OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOO

The Main method does not need a string[] input parameter. It can be declared as: static void Main() - m0sa
@m0sa It's used to pick up the height from the command line arguments. You can of course make it shorter by hardcoding the height. - ICR
Hmm, looks like my BF answer at least beats something... - Esolanging Fruit
40
[+1] [2011-12-07 07:27:34] MtnViewMark

Haskell, 73 characters

main=mapM_ putStrLn$"        *":take 9(iterate((++"00").tail)"        0")

And the output:

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

41
[+1] [2011-12-07 08:53:08] Steven Rumbalski

Python, 64

Yet another python answer.

def f(i,c='0'):print' '*(9-i)+c*(i*2+1)
f(0,'*')
map(f,range(9))

42
[+1] [2011-12-07 15:57:22] Vladimir

PHP, 109 characters

for($i=10,$j=1,$k=0;$i;$i--,$j+=2,$k=2)echo str_pad(str_repeat($j<2?'*':0,$j-$k),$i+$j-(!$k?1:2),' ',0)."\n";

Not the shortest code possible, but easily resizable with changing only the value of $i.


43
[+1] [2011-12-07 19:07:42] m0sa

F#, 167 bytes

let r n s=String.replicate n s
let rec x h i=
 let w=r i" "
 match h with|0->w+"*\n"|1->(x(h-1)i)+w+"0\n"|z->(x(h-1)(i+1))+w+(r(z+z-1)"0")+"\n"
printfn "%s"(x 8 0)

44
[+1] [2011-12-08 14:38:52] Armand

Java, 155 127

enum t{_;{for(char c=42,i=9,j;--i<0;c=48){j=i;String b="";while(--j>0)b+=" ";while(++j<(10-i)*2)b+=c;System.out.println(b);}}}

and a tree

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

45
[+1] [2011-12-09 05:20:34] scott

Ruby, 51 bytes

puts' '*8+'*';9.times{|a|puts' '*(8-a)+'0'*(a*2+1)}

Output:

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

Alas, there's already a shorter Ruby solution. - Ilmari Karonen
46
[+1] [2011-12-12 02:53:49] bnjf

with sed:

$ echo $'\n\n\n\n\n\n\n\n\n'|sed -e '1{ s/^/        */;h;}' -e '2,${x;/ 0/s//000/;/\*/s//0/;h;}'

Output:

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

47
[+1] [2011-12-19 22:02:39] MARTIN Damien

VALA, 181

void main(string[] argv){int i,h=int.parse(argv[1]);stdout.printf(string.nfill(h-1,' ')+"*\n");for(i=0;i<h;i++)stdout.printf(string.nfill(h-i-1,' ')+string.nfill(2*i+1,'0')+"\n");}

The result :

[damien@caturday ~]$ ./christmas_tree 5
    *
    0
   000
  00000
 0000000
000000000

48
[+1] [2016-01-10 09:07:28] Nitin Nizhawan

Scala, 73 bytes

var(h,c)=(10,"*");0+:(0 to h-2)map{i=>println(" "*(h-i)+c*(i*2+1));c="0"}

Output

          *
          0
         000
        00000
       0000000
      000000000
     00000000000
    0000000000000
   000000000000000
  00000000000000000

Welcome to Programming Puzzles and Code Golf. This is a very well golfed answer (+1), however it could benefit from a code breakdown and explanation. - wizzwizz4
49
[+1] [2016-12-07 21:14:13] DJMcMayhem

V [1], 13 bytes

17é0òÄlxx>òr*

Try it online! [2]

It's fun to beat the accepted answer by a huge margin. :D

Explanation:

17é0            " Insert 17 '0's
    ò     ò     " Recursively:
     Ä          "   Copy this line upwards
      l         "   Move one char to the right
       xx       "   Delete two characters
         >      "   Indent this line
           r*   " Replace the last character with an asterisk
[1] http://github.com/DJMcMayhem/V
[2] http://v.tryitonline.net/#code=MTfDqTDDssOEbHh4PsOycio&input=

50
[+1] [2018-10-08 11:36:32] mazzy

Powershell, 38 bytes

' '*8+'*'
8..0|%{' '*$_+'0'*(17-2*$_)}

Output:

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

Powershell with parameter, 49 bytes

param($h)' '*$h+'*'
$h..0|%{' '*$_+'0'*(17-2*$_)}

51
[+1] [2020-03-29 08:05:51] ScriptKidd

BATCH, 96 90 83 73 71 bytes

Fixed height=10:

@set[=          0
@echo%[:0=*%
:0
@echo%[%
@set[=%[:~1%00
@goto:0%[:~1%

Saved 6 bytes by replacing \r\n line terminators with \n (still works)
P.S I'm new to golf, so I'm not sure if pause is required. Removed @pause, saved 7 bytes.
2020/4/30 - Abused token delimiters [, golfed 2 bytes.


I would say you do not need \n@pause, since it does not change your program's output. - Jonathan Frech
@JonathanFrech thanks, it's removed - ScriptKidd
52
[+1] [2020-04-01 12:46:58] Kevin Cruijssen

Charcoal [1], fixed height: 10 8 bytes [2]

↓*G↙→→⁹0

-2 bytes thanks to @Neil.

Try it online (verbose) [3] or try it online (pure) [4].

Explanation:

Print the "*", and move the cursor down:

Print(:Down, "*");
↓*

Draw a polygon in the shape of a triangle, with the initial arm as size 9 and using the character "0" as filler:

Polygon(:DownRight, :Left, :Left, 9, "0");
G↙→→⁹0

Variable height through input: 14 9 bytes [5]:

↓*G↘←←⊖θ0

-5 bytes thanks to @Neil.

Try it online (verbose) [6] or try it online (pure) [7].

Explanation:

Print the "*", and move the cursor down:

Print(:Down, "*");
↓*

Draw a polygon in the shape of a triangle, with the initial arm as size input-1 and using the character "0" as filler:

Polygon(:DownRight, :Left, :Left, Decremented(q), "0");
G↘←←⊖θ0
[1] https://github.com/somebody1234/Charcoal/wiki/Tutorial
[2] https://github.com/somebody1234/Charcoal/wiki/Code-page
[3] https://tio.run/##S85ILErOT8z5/z@gKDOvRMPKJb88T0dBSUtJ05orID@nMj0/DyIYlJmeUaKjYOWTmoagLIFKDYBK////r1uWAwA
[4] https://tio.run/##S85ILErOT8z5//9R22St93uWP2qb@ahtEgg17jT4/x8A
[5] https://github.com/somebody1234/Charcoal/wiki/Code-page
[6] https://tio.run/##S85ILErOT8z5/z@gKDOvRMPKJb88T0dBSUtJ05orID@nMj0/DyIYlJmeUaKjYOWTmoagXFKTi1JzU/NKUlM0CjWB@gyA@v7/NzT9r1uWAwA
[7] https://tio.run/##S85ILErOT8z5//9R22St93uWP2qb8ahtAgh1TTu3w@D/f0NTAA

(1) By reversing the order of drawing, you get ↓*G↙→→⁹0 for 8 bytes. - Neil
@Neil Thanks! And the same golfs 3 bytes in the variable answer, + 2 more because the input can be done implicitly for integers as well now. (This wasn't the case prior, was it? I can remember it wasn't when I posted my first Charcoal answer a few years back.) - Kevin Cruijssen
As far as I can remember, I think Decremented has always cast from string to number first. - Neil
I think you forgot to update G↗↘←⊖θ0M⊖θ↑* to your latest linked code in your explanation? - Neil
@Neil Oops, thanks for noticing. - Kevin Cruijssen
53
[+1] [2020-10-14 02:42:28] DLosc

Notepad++ [1], 27 keystrokes

0000<Ctrl-A><Ctrl-D><Ctrl-A><Ctrl-D><Home>0<Ctrl-Shift-R><Ctrl-D><Del><Backsp><Space>
→<Ctrl-Shift-R><Ctrl-Shift-P><Ctrl-Shift-P><Ctrl-Shift-P><Ctrl-Shift-P>
<Ctrl-Shift-P><Ctrl-Shift-P><Ctrl-Shift-P><Ctrl-D><Backsp>*

(Newlines included only for readability.)

Explanation

We'll build the tree from the bottom up:

The setup

Starting with four 0s, we CtrlA CtrlD (select all, duplicate) twice to get sixteen 0s. We need seventeen 0s on the bottom row, so we go Home and add another one. The cursor is now positioned right after the first 0 on the line.

The macro

CtrlShiftR starts recording a macro, which we'll use to generate each line from the one below it:

  • CtrlD duplicates the line, leaving the cursor on the upper of the two copies
  • Since the cursor is just after the first 0 on the line, Del Backsp Space removes two 0s and prepends a space
  • Finally, moves one character rightward, so that we are once again right after the first 0 on the line

A second CtrlShiftR ends the macro, and then CtrlShiftP seven times calls the macro repeatedly to generate the rest of the body of the tree.

The finishing touch

For the star, we need only duplicate the top row with CtrlD, remove the 0 with Backsp, and replace it with a *.

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000
[1] https://notepad-plus-plus.org

54
[+1] [2020-10-14 15:16:19] Shaggy

Rockstar [1], 72 bytes

say " "*8+"*"
X's0
while 9-X
let Y be 8-X
say " "*Y+0+"0"*X*2
let X be+1

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

[1] https://codewithrockstar.com/
[2] https://codewithrockstar.com/online

55
[+1] [2021-05-27 03:27:27] DLosc

Jelly [1], 17 16 bytes

⁶ẋ8⁾*¶9µ>þa⁶UŒBY

Try it online! [2]

This is my first time golfing in Jelly; I'm sure this could be golfed further. Advice welcome. :^)

Explanation

⁶                 Space character
 ẋ8               Repeated 8 times
                  Since this niladic chain doesn't connect to anything, just output it
   ⁾*¶            Two-character string containing * and newline
                  Since this niladic chain doesn't connect to anything, just output it
      9µ          Apply the following monadic chain to a starting value of 9:
        >þ        Make a 9x9 table, where each entry is 1 if the column number is
                  greater than the row number, 0 if not
          a⁶      Logical AND with space (replaces the 1's with spaces)
            U     Reverse each row
             ŒB   Bounce, mirroring each row to the right
               Y  Join with newlines
[1] https://github.com/DennisMitchell/jelly
[2] https://tio.run/##y0rNyan8//9R47aHu7otHjXu0zq0zfLQVrvD@xKBYqFHJzlF/v8PAA

56
[+1] [2021-05-27 04:36:03] emanresu A

Vyxal [1], 18 bytes

9\*꘍₀(,9n-\0n›*꘍øm

Try it Online! [2]

Fairly well golfed.

9                  # 9
 \*                # '*'  
   ꘍               # ' ' * 9 + '*'
    ₀(             # 10 times
      ,            # output
       9n-         # 9 - (iteration number)
          \0       # String '0'
            n›     # iteration number + 1
              *    # That many 0s
               ꘍   # (9 - (iteration number)) spaces + 0s
                øm # Palindromised

Tree:

         *
         0         
        000        
       00000       
      0000000      
     000000000     
    00000000000    
   0000000000000   
  000000000000000  
 00000000000000000 
[1] https://github.com/Lyxal/Vyxal
[2] http://lyxal.pythonanywhere.com?flags=&code=9%5C*%EA%98%8D%E2%82%80%28%2C9n-%5C0n%E2%80%BA*%EA%98%8D%C3%B8m&inputs=&header=&footer=

57
[+1] [2021-05-27 06:57:55] dingledooper

Python 2 [1], 49 bytes

n=-1
exec"print' '*(8-n/2%n),n*'0'or'*';n+=2;"*10

Try it online! [2]

Python 3 [3], 47 bytes

n=-1
while n<19:print(f"{n*'0'or'*':^19}");n+=2

Try it online! [4]

[1] https://docs.python.org/2/
[2] https://tio.run/##K6gsycjPM/r/P89W15ArtSI1WamgKDOvRF1BXUvDQjdP30g1T1MnT0vdQD2/SF1L3TpP29bIWknL0OD/fwA
[3] https://docs.python.org/3/
[4] https://tio.run/##K6gsycjPM/7/P89W15CrPCMzJ1Uhz8bQ0qqgKDOvRCNNqTpPS91APb9IXUvdKs7QslZJ0zpP29bo/38A

58
[+1] [2023-05-02 19:28:23] emirps

Vyxal [1] C, 9 bytes

17~∷\0*×p

Try it Online! [2]

17~       # the range 1..17 filtered by
   ∷      # is odd
    \0*   # "0" repeated n times for n in those odd nums
       ×p # with an asterisk prepended
          # C flag joins by newlines and centers output
[1] https://github.com/Vyxal/Vyxal
[2] https://vyxal.pythonanywhere.com/?v=1#WyJDIiwiIiwiMTd+4oi3XFwwKsOXcCIsIiIsIiJd

59
[0] [2011-12-06 07:24:44] Wade Tandy

C 145

Takes its heigh param from argc, so set the number of rows by setting the number of arguments:

#define x printf
int main(int c){int i=-1,j=0;while(j++<c)x(" ");x("*");while(++i<c){for(j=-2;++j<c-i;)x(" ");for(j=0;++j<2*i;)x("0");x("\n");}}

To generate the ten line spec output, you call:

christmastree 1 2 3 4 5 6 7 8 9

Or if you'd prefer to hardcode the height, change c in this version:

#define x printf
int main(){int i=-1,j=0,c=10;while(j++<c)x(" ");x("*");while(++i<c){for(j=-2;++j<c-i;)x(" ");for(j=0;++j<2*i;)x("0");x("\n");}}

60
[0] [2011-12-06 11:06:56] Anders

Python, 79 chars

s,h=1,10;print " "*(h-s/2)+"*"
for x in range(h):print " "*(h-s/2)+"0"*s;s=s+2
          *
          0
         000
        00000
       0000000
      000000000
     00000000000
    0000000000000
   000000000000000
  00000000000000000
 0000000000000000000

61
[0] [2011-12-07 00:04:37] Tommy

R, 68 characters

s=sprintf;cat(s('%10s','*'),s('% *s%0*d',9:1,'',1:9*2-1,0),sep='\n')

And here's a parameterized version:

n=12 # Tree height (without star)
s=sprintf;cat(s('%*s',n+1,'*'),s('% *s%0*d',n:1,'',1:n*2-1,0),sep='\n')

Old version, 85 characters

cat('         *\n         0\n');cat(sprintf('% *d%0*d',9:2,0,seq(2,16,2),0),sep='\n')

I know, not the prettiest - R is not that great at formatting output using compact code.


62
[0] [2012-02-16 13:09:50] Paolo

R, 89 chars

A fixed-height 10-layer tree can be done in 89 characters:

cat(rep("",9),"*\n");for(i in 1:10)cat(rep(" ",10-i),rep("0",seq(1,20,2)[i]),"\n",sep="")

Providing a height parameter takes it to 97:

h=10;cat(rep("",h-1),"*\n");for (i in 1:h)cat(rep(" ",h-i),rep("0",seq(1,2*h,2)[i]),"\n",sep="")

Output:

         *
         0
        000
       00000
      0000000
     000000000
    00000000000
   0000000000000
  000000000000000
 00000000000000000
0000000000000000000

63
[0] [2012-06-21 18:04:24] Event_Horizon

PHP-275 Chars

Count is not including any whitespace, resizable by changing function parameter number:

function Tenenbaum($n)
{
$r="<br/>";
$x=2;
$v=" ";
$z="0";
$l=str_repeat($v,$n);
echo "$l*$r".$l."0$r";

for($i=1;$i<=$n;$i++)
{
$s=$n-3;
$p=str_repeat($v,$s);
$q=str_repeat($z,5);
echo str_repeat($v,$n-$i).str_repeat($z,$i+$x).$r;

if($i==$n)
{
echo "$p$q$r$p$q$r$p$q";
}
$x+=1;
}
}

Tenenbaum(20);

Output:

                    *
                    0
                   000
                  00000
                 0000000
                000000000
               00000000000
              0000000000000
             000000000000000
            00000000000000000
           0000000000000000000
          000000000000000000000
         00000000000000000000000
        0000000000000000000000000
       000000000000000000000000000
      00000000000000000000000000000
     0000000000000000000000000000000
    000000000000000000000000000000000
   00000000000000000000000000000000000
  0000000000000000000000000000000000000
 000000000000000000000000000000000000000
00000000000000000000000000000000000000000
                 00000
                 00000
                 00000

64
[0] [2012-07-03 17:43:48] NRGdallas

CSV, 133 bytes

Thought I would Cheat Just a little on this one for a few laughs :)

        0,
       000,
      00000,
     0000000,
    000000000,
   00000000000,
  0000000000000,
 000000000000000,
00000000000000000

65
[0] [2012-07-26 22:35:18] Leigh

PHP - 75

<?=($p='          ').'*
';for($s=' 0';$p=substr($p,1);$s.='00')echo"$p$s
";

For variable heights of 12 or below, modify the hard-coded padding in the above. (Code gets smaller the lower the height)

For variable heights of 13 or more use the following, height param is the second argument to str_pad. (Code starts at 77 bytes and doesn't grow as fast as the version with static padding)

<?=($p=str_pad('',13)).'*
';for($s=' 0';$p=substr($p,1);$s.='00')echo"$p$s
";

Output of php -d short_open_tag=1 tree.php

          *
          0
         000
        00000
       0000000
      000000000
     00000000000
    0000000000000
   000000000000000
  00000000000000000

66
[0] [2012-08-02 20:20:22] Kazark

VimScript: 92 characters

I am working at learning Vim and it occurred to me that it could be a neat platform for code golfing. I don't know how to script in Vim that well yet, so any optimization suggestions are appreciated. Note: ^[ does not mean a literal caret next to a literal bracket, but is Vim's way of displaying a literal ESC character in the text.

norm8a ^[a*^[9o^[17a0^[ka ^[15a0^[k2a ^[13a0^[k3a ^[11a0^[k4a ^[9a0^[k5a ^[7a0^[k6a ^[5a0^[k7a ^[3a0^[k8a ^[a0

Here is the output. One of the unique things about this answer is that the output is created in a buffer in Vim (use a :new buffer). The brackets indicate the final cursor location, which ended up where it did for optimization reasons but I think that is cool:

        *
       [0]
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000

Updated: 71 characters

Using mapping to reduce number of characters:

map b a0^[k
map c a ^[
norm8ca*^[9o^[17bc15b2c13b3c11b4c9b5c7b6c5b7c3b8ca0

Updated: 69 characters

Use punctuation instead of letters for the mapped characters in order to save two space characters.

map- a0^[k
map. a ^[
norm8.a*^[9o^[17-.15-2.13-3.11-4.9-5.7-6.5-7.3-8.a0

Updated: 66 characters

Use nn ("normal, no remap") for map to save 2 letters. Also swap final a0 for -. Note that this results in the cursor resting on the star in the final output rather than on the tip-top of the tree right below the star.

nn- a0^[k
nn. a ^[
norm8.a*^[9o^[17-.15-2.13-3.11-4.9-5.7-6.5-7.3-8.-

Updated: 63 characters

Moving/substituting a few more things allows yet another reduction (ignore the , -> . change):

nn- a0^[O^[
nn, a ^[
norm17-,15-2,13-3,11-4,9-5,7-6,5-7,3-8,-8,a*

67
[0] [2012-08-18 19:05:25] Haile

Common Lisp - 100 [nonblank] chars

No Common Lisp solutions? =) Here's mine:

(or 
   (format t "~17:@<*~>~%") 
   (format t "~{~17:@<~{0~*~}~>~%~}" 
      (loop for x upto 8 collect 
         (make-list (1+ (* 2 x))))))

result:

        *        
        0        
       000       
      00000      
     0000000     
    000000000    
   00000000000   
  0000000000000  
 000000000000000 
00000000000000000

for higher trees just replace "8" with (height - 2) and "17" with 1+2x(height-2). Here's a 14 rows tree:

CL-USER> (or 
          (format t "~25:@<*~>~%") 
          (format t "~{~25:@<~{0~*~}~>~%~}" 
                  (loop for x upto 12 collect 
                       (make-list (1+ (* 2 x))))))
            *            
            0            
           000           
          00000          
         0000000         
        000000000        
       00000000000       
      0000000000000      
     000000000000000     
    00000000000000000    
   0000000000000000000   
  000000000000000000000  
 00000000000000000000000 
0000000000000000000000000

68
[0] [2014-02-19 16:35:31] RobIII

C#, Fixed height, 136 chars

class P{static void Main(){for(int i=0;i<10;i++)System.Console.WriteLine((i>0?new string('0',(i-1)*2+1):"*").PadLeft(10+(i>0?i-1:0)));}}

Formatted:

class P
{
    static void Main()
    {
        for (int i = 0; i < 10; i++)
            System.Console.WriteLine((i > 0 ? new string('0', (i - 1) * 2 + 1) : "*").PadLeft(10 + (i > 0 ? i - 1 : 0)));
    }
}

Output when run:

         *
         0
        000
       00000
      0000000
     000000000
    00000000000
   0000000000000
  000000000000000
 00000000000000000

Variable height: 165 chars

Use commandline parameter to specify height

class P{static void Main(string[]a){int h=int.Parse(a[0]);for(int i=0;i<h;i++)System.Console.WriteLine((i>0?new string('0',(i-1)*2+1):"*").PadLeft(h+(i>0?i-1:0)));}}

Formatted:

class P
{
    static void Main(string[] a)
    {
        int h = int.Parse(a[0]);
        for (int i = 0; i < h; i++)
            System.Console.WriteLine((i > 0 ? new string('0', (i - 1) * 2 + 1) : "*").PadLeft(h + (i > 0 ? i - 1 : 0)));
    }
}

Output for foo.exe 15:

              *
              0
             000
            00000
           0000000
          000000000
         00000000000
        0000000000000
       000000000000000
      00000000000000000
     0000000000000000000
    000000000000000000000
   00000000000000000000000
  0000000000000000000000000
 000000000000000000000000000

69
[0] [2014-02-19 20:40:33] Christopher King

Haskell

tree x=unlines $ (insert 1 '*'):[insert o '0'|o<-[1,3..r]]
    where insert n c=let sur = replicate ((r-n) `div` 2) ' ' in sur++(replicate n c)++sur
          r=2*x+1

Here is the output:

λ <*Main>: putStr $ tree 10
          *          
          0          
         000         
        00000        
       0000000       
      000000000      
     00000000000     
    0000000000000    
   000000000000000   
  00000000000000000  
 0000000000000000000 
000000000000000000000

70
[0] [2016-12-07 00:40:53] Hyan Christian

JavaScript, 108 bytes 92 bytes

i=9,n=Array(i).join(' '),s='0',a=[n+'*'];while(i--)a.push(n.substr(0,i)+s),s+='00';console.log(a.join('\n'))

edited:

i=10,n=' '.repeat(i-1),s='0',t=n+'x';for(;i--;s+='00')t+='\n'+n.substr(0,i)+s;console.log(t)

ungolfed:

i=10,n=' '.repeat(i-1),s='0',t=n+'x';

for(;i--;s+='00')t+='\n'+n.substr(0,i)+s;

console.log(t);

Welcome to PPCG! Nice first post! - Riker
Welcome to PPCG! n='<9 spaces>' will save you a few bytes over your current setup. You can also save a few bytes by switching to a for loop, like so: for(;i--;s+='00')a.push(n.substr(0,i)+s); You can also read through the Tips for golfing in JavaScript thread for more ways to golf, if you'd like. - ETHproductions
@ETHproductions that's very good tips, thanks - Hyan Christian
71
[0] [2016-12-07 05:15:53] ETHproductions

JavaScript, 71 bytes

for(i=z='10';i--;z+='00')console.log('        *'.slice(0,i)+z.slice(3))

This challenge seemed to be suffering from a distinct lack of super-short JavaScript answers, so I thought I'd try to make up for that. This is the shortest ES5 solution I have found thus far.

Test snippet

for(i=z='10';i--;z+='00')console.log('        *'.slice(0,i)+z.slice(3))


72
[0] [2016-12-07 20:02:50] Esolanging Fruit

Brainf*ck, 163 bytes

This could be golfed further, but this is my first serious attempt at golfing in general, so oh well...

++++++++++[->+>+>+<<<]>>>++++++[->>++>+++<<<]>>.<<<-[>>>.<<+<-]>>>>------.++++++>+<<<<+.-[-[-<+>>+<]<[->+<]>>>..<[->.<]>>>[->+>+<<]>[-<+>]>[-<<<.>>>]<<++<<<<<<.>>]

Output:

          *
          0
         000
        00000
       0000000
      000000000
     00000000000
    0000000000000
   000000000000000
  00000000000000000

73
[0] [2016-12-07 22:16:47] HaLo2FrEeEk

jQuery, 160 152 143 bytes

Well, I recognize that it's late, and that it didn't beat the other jQuery entries, but it's been a LONG time since I've done any javascript, so here goes:

$.fn.x=function(h){for(var i=1,o=" ".repeat(h-2)+"*\n";i++<h;)o+=(i==h?"0".repeat(i+(i-3)):" ".repeat(h-i)+"0".repeat(i+(i-3)))+"\n";return o};

Can be run from your browser's javascript console with $().x(10), and accepts any height parameter. Keep in mind, Chrome's console puts a quotation mark at the beginning and end of console output, so that makes the * appear out of place, but it's not.


74
[0] [2018-02-01 16:33:19] jrtapsell

Kotlin [1], 113 bytes

{(0..9).map{print(' ')}
println('*')
(0..9).map{(it..9).map{print(' ')}
(0..it-1).map{print("00")}
println('0')}}

Beautified

{
    (0..9).map { print(' ') }
    println('*')
    (0..9).map {
        (it..9).map { print(' ') }
        (0..it-1).map { print("00") }
        println('0')
    }
}

Test

var f:()->Unit =
{(0..9).map{print(' ')}
println('*')
(0..9).map{(it..9).map{print(' ')}
(0..it-1).map{print("00")}
println('0')}}

fun main(args: Array<String>) {
    f()
}

TIO

TryItOnline [2]

[1] https://kotlinlang.org
[2] https://tio.run/##bcxBCsIwEAXQ/Zxi6CYzQkNcWrTgGcQDZNMSbMcSR0FCzh6jqyz8qw//8W93XYIUePmI00Dcj1cJiqeSyFl7YLv6LW0xiJJBwxl+fREyO8PQGAr6139J0H7fLp1zXXvlKswFpqfg6oOQj/NjwHOM/n28aFXzyJgAayZiyOUD

75
[0] [2018-02-01 18:40:42] Taylor Raine

uBASIC [1], 63 bytes

0?Tab(9);"*":ForI=0To8:?Tab(9-I);:ForJ=0To2*I:?0;:NextJ:?:NextI

Try it online! [2]

[1] https://github.com/EtchedPixels/ubasic
[2] https://tio.run/##K01KLM5M/v/fwD4kMUnDUtNaSUvJyi2/yNPWICTfwgoiquupaQ0S9AIJGml5WtkbWFv5pVaUeFnZg2nP//8B

76
[0] [2018-02-01 18:58:57] Taylor Raine

MY-BASIC [1], 95 bytes

S="         *"
Print S;
For I=0 To 8
Print Left(S,9-I)d
For J=0 To 2*I
Print 0
Next
Print;
Next

Try it online! [2]

[1] https://github.com/paladin-t/my_basic
[2] https://tio.run/##y63UTUoszkz@/z/YVkkBBrSUuAKKMvNKFIKtudzyixQ8bQ0UQvIVLKCiPqlpJRrBOpa6npopYHkviLyRlidUhQGXX2pFCYRjDWb//w8A

77
[0] [2018-02-01 21:55:43] Robert Benson

AWK [1], 71 bytes

{for(;$1--;)printf"%"$1-(a==0)"s%0"2*++F-3(a?"d":"s")"\n","",a++?0:"*"}

Try it online! [2]

It seems like some simplification should be possible, but I can't find it.

NOTE: The TIO link has a few extra bytes to allow printing multiple trees.

        *
        0
       000
      00000
     0000000
    000000000
   00000000000
  0000000000000
 000000000000000
00000000000000000
[1] https://www.gnu.org/software/gawk/manual/gawk.html
[2] https://tio.run/##SyzP/v@/Oi2/SCPR1s3WwFrFUFfXWrOgKDOvJE1JVQnIBUrYGmgqFasaKBlpaWu76RprJNorpShZKRUraSrF5CnpKCnpJGpr2xtYKWkp1f7/b2jAZWgJAA

78
[0] [2018-02-01 23:35:31] ngn

APL (Dyalog Classic) [1], 25 bytes

' *0'[(⊣⌿⍪+⍨)(⊖,~)∘.≤⍨⍳⎕]

Try it online! [2]

        *         
        0         
       000        
      00000       
     0000000      
    000000000     
   00000000000    
  0000000000000   
 000000000000000  
00000000000000000 

it's resizable:

                   *                    
                   0                    
                  000                   
                 00000                  
                0000000                 
               000000000                
              00000000000               
             0000000000000              
            000000000000000             
           00000000000000000            
          0000000000000000000           
         000000000000000000000          
        00000000000000000000000         
       0000000000000000000000000        
      000000000000000000000000000       
     00000000000000000000000000000      
    0000000000000000000000000000000     
   000000000000000000000000000000000    
  00000000000000000000000000000000000   
 0000000000000000000000000000000000000  
000000000000000000000000000000000000000 
[1] https://www.dyalog.com/
[2] https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob2pm/qO2CQZcjzra0/6rK2gZqEdrPOpa/Khn/6PeVdqPeldoArnTdOo0H3XM0HvUuQQo8qh3M1Bf7H@glv9pXJZcXGlcRgYA

79
[0] [2018-02-02 00:11:00] Addison Crump

Java (OpenJDK 8) [1], 165 bytes

I saw some possible changes in the existing Java answer and thought I'd add my answer. (trims off 65 bytes, so I'm pretty proud tbh)

interface p{static void main(String[]a){String s="        ",o=s+"*";for(int i=0;i<9;i++){o+="\n"+s.substring(i);for(int j=0;j<=2*i;j++)o+=0;}System.out.println(o);}}

Try it online! [2]

[1] http://openjdk.java.net/
[2] https://tio.run/##PcxBDoIwFATQqzRdtVQJcWdKT8ESXVQo5lfpJ/xCYghnr40mzGoWb8bb1Z5xcsH3r5QgRDcPtnNs2ijaCB1bEXo2WgiiiTOEZ3u3cvtXRoazI/yEhhQvuB5wFvmJgak01FcNSskNleG3wBWVtDzotxcgD@uz9bW5FKB95llXem8@FN1Y4hLLKQ/iOwiUet9T@gI

80
[0] [2018-02-02 00:20:56] Titus

PHP, 69 bytes

while($i<10)printf("%".(8+$i+!$i)."s
",$i++?str_pad(0,$i*2-3,0):'*');

Run with php -nr '<code>' or try it online [1].


Resizable version, 76+1 bytes (run as pipe with -nR):

while($i<$argn)printf("%".($argn+$i+!$i)."s
",$i++?str_pad(0,$i*2-3,0):'*');
[1] http://sandbox.onlinephpfunctions.com/code/6a9ea80b14045c1fc01af98cf45511ff39ff2266

81
[0] [2018-10-08 02:39:29] JohnWells

Kotlin [1], 108 bytes

A few years late, but I was searching for something else and it was in my search results. Accepts a input for the rows. Fixing it to 10 rows saves 6 bytes (code below).

{n:Int->(0..n).map{if(it<1)" ".repeat(n)+"*"
else " ".repeat(n-it+1)+"0".repeat(it*2-1)}.joinToString("\n")}

Try it online! [2]

Output: * 0 000 00000 0000000 000000000 00000000000 0000000000000 000000000000000 00000000000000000 0000000000000000000 Hardcoded with 10: {(0..10).map{if(it<1)" ".repeat(10)+"*" else " ".repeat(11-it)+"0".repeat(it*2-1)}.joinToString("\n")}

[1] https://kotlinlang.org
[2] https://tio.run/##dVXBbuNGDL37KxhfKmUdebzYQ2GkC2wXW6DFAi3QHHsZW5Q1tTSjzozieIN8e/qGIydxNutLIoqP5CMfqb2LnbGPyyV99qwj19Q4T7E1gbauZtq5rqFtq7uO7Y7XMzi2MQ5hvVym9@l1FaLe7vkOXnCptq5f/jdyiMbZsPywWn1IoL@8sZE0fW69CbHXgW488yy9umkZ5inD7KWzNVt@gYhA0MHElkz8KZA7WEJqTzomUESY6AYag7E7eQqt8xGFZCaDC8FsOq4kYYqVUBIAZLUlHSIj1Z6KyxLPdY6Ycm5cfUxOva4F5MZIriH1FIn6EWk2TCtF3h0CtWbXVvTllv0xGSRT68auTk6DdwP7DiFtzTb13FhJdtBH/NUxPSTI4PnWuDGkEKQ90za5ewAcIgvE8h1qsWD1yR4TZmdu2QpAamr1LdN76h3QKqToOdUp9CJhMDse4jR5psb4IEFzMSbkbkqrc1uED2@drRd0aM22RR4MxIJTgqncY89h7BJe3F3PkBVG05k9i8LWMuzn3@X5ozp7VOrsWalzg1KvLEq9Nin1nU2p741KvWFVr39ZuQbawNrspXWga75pKIxaxvijKCOIYCGY3IMmHmSOsiqBiqnz8px6MyEH7TXaxb7M@9CxDryAGRKVYeTWitCT/CDGoxt9Fnp07oIE9@VuwMAgF6glYB2TX6f7Ta0r@g0Vs8bkIJUF7diyx/onlCxXiNjBXXZLCb@xd9k17M3wvBqgnNUw6C0H0ccwxmfBICmW8jmOgNKKiPAasxvRDndC5CDR5SSnHbRjv4HcXZMgqZDsU5swdPo4aS1t3QaS7Jm44x6LEhJdnTAdDkhFfzismVCGPZ4wck9waviAO4hxcjww2@mg9NhMZNKUbkrHp67MmtGmLUaxocjVrel3G0v6ZZYkVKiqyuay6vVA97OsQNNQYSJd06qcnYQ7p3nlecDtnSKV7@aX8@k1d4F/7Hll4rsV3NWT3cTL91dT8IfqXxC@cX9LzcX8Hzuf1MQecu2lBU@XPXPqtbGF9ruwpk/e6@N1Bn8sQQFBAf4q8iE4b9OBT3M4aedpvhVcbzH7QdoB0Er9TJsjTvHjvV2jT1cfpUPSnHvToOzrVfmSXu5BYn/G@oeE3@L68Ci5b9IFZl2fPgoy9Ma7zN9YqHVxmmWu9kRjkdUs3yITE6mIWHmWYi2GIkX@Ct0U5cVFFR24FWVZTr36006XFY1aYDd7yNXYp2ySqOZGY5OnzG9mfaCtjlBtwd47CO2mBYd0Z8qXxXS2mP@q6xOj/BWcooeLeXlW9kqVpUSWpMeZ/JOG/7hS/wM

You can to save some bytes: {n:Int->(-1..n).map{if(it<0)"".padEnd(n)+"*" else "".padEnd(n-it)+"0".repeat(it*2+1)}.joinToString("\n")} - mazzy
82
[0] [2020-04-01 11:51:39] user92069

Erlang (escript) [1], 134 bytes

The tree is resizable.

r(-1,_)->"";r(X,Y)->lists:duplicate(X," ")++lists:duplicate(Y,"0")++"\n"++r(X-1,Y+2).
t(X)->lists:duplicate(X-1," ")++"*\n"++r(X-1,1).

Try it online! [2]

[1] http://erlang.org/doc/man/escript.html
[2] https://tio.run/##bYzBCsIwDEDv/YqSU2Pb4bw5Yd@xoiJlVgnUOtqKn18jXkTMKbzkvZCjT1cbypxpqU20rGxvTmhHgF1Wk3G8Riq1DOfHEmn2NTAFCaj1L3cG1m8OhwRas80ppzfYiaqmfx2@f0qw@lJ67NrNU1L7I0o7CslD9@HyzMRSVVvkhxc

83
[0] [2020-04-01 11:58:53] Kevin Cruijssen

05AB1E [1], fixed height: 11 bytes [2]

¾17ÅÉ×'*š.c

Try it online. [3]

Variable height through input: 12 11 bytes [4]:

ηÍÅÉ×'*š.c

Try it online. [5]

Explanation:

¾             # Push 0 (push the counter_variable, which is 0 by default)
 17ÅÉ         # Push a list of the positive odd numbers <= 17: [1,3,5,7,9,11,13,15,17]
     ×        # Repeat the 0 that many times as string:
              #  ["0", "000", "00000", ..., "00000000000000000"]
      '*š    '# Prepend a "*": ["*", "0", "000", "00000", ..., "00000000000000000"]
         .c   # Centralize each line by padding with leading spaces
              # (which also implicitly joins a list by newlines at the same time)
              # (after which it is output implicitly as result)

Î             # Push 0 and the input-integer
 ·            # Double the input
  Í           # Decrease it by 2
   ÅÉ×'*š.c  '# Same as above
[1] https://github.com/Adriandmen/05AB1E/wiki/Commands
[2] https://github.com/Adriandmen/05AB1E/wiki/Codepage
[3] https://tio.run/##yy9OTMpM/f//0D5D88OthzsPT1fXOrpQL/n/fwA
[4] https://github.com/Adriandmen/05AB1E/wiki/Codepage
[5] https://tio.run/##yy9OTMpM/f//cN@h7Yd7D7ce7jw8XV3r6EK95P//DU0B

84
[0] [2020-04-13 08:22:03] Muskovets

C, 128

h=10;y,w,i,j;main(){for(y=-1;y<h;y++){w=1+max(y,0)*2;i=((h*2)-w)/2;for(j=0;j<i+w;j+1)printf(j<i?" ":y+1?"0":"*");printf("\n");}}
         *
         0
        000
       00000
      0000000
     000000000
    00000000000
   0000000000000
  000000000000000
 00000000000000000
0000000000000000000

h is the tree's height without the star.


85
[0] [2020-10-19 11:04:42] Shaggy

Japt [1] -R [2], 12 11 bytes [3]

AÇçT êÃh* û

Test it [4]

AÇçT êÃh* û     :(Remove A to input the height instead)
A               :10
 Ç              :Map the range [0,A) (or [0,input))
  ç             :  Repeat
   T            :    0
     ê          :  Palindromise
      Ã         :End map
       h*       :Replace the first element with "*"
          û     :Centre pad with spaces to the length of the longest
                :Implicit output joined with newlines
[1] https://github.com/ETHproductions/japt
[2] https://codegolf.meta.stackexchange.com/a/14339/
[3] https://en.wikipedia.org/wiki/ISO/IEC_8859-1
[4] https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LVI&code=QcfnVCDqw2gqIPs

86
[0] [2021-05-27 04:30:22] Samuel Waller

/// [1], 57 bytes

/i/         /i*/> /
i0\/ \\0\/a\\a\/\/a\\a\/000\/>//>//>i

Try it online! [2]

Normally I would have another replacement for the escaped "/" in the loop bit, but it happens to be the same length without so why not.

Change the number of spaces in the first line, after the /i/. Technically, there is one less space that the 'size' but size 0, 1 etc aren't defined so I don't think it matters.

[1] https://esolangs.org/wiki////
[2] https://tio.run/##K85JLM5ILf7/Xz9TXwEG9DO19O0U9LkyDWL0FWJigGRiTExijD6MNjAACtnpg1Hm//8A

87