Skip to main content
added 130 characters in body
Source Link
Tommy
  • 931
  • 7
  • 7

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.

R, 68 characters

s=sprintf;cat(s('%10s','*'),s('% *s%0*d',9:1,'',1:9*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.

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.

added 106 characters in body
Source Link
Tommy
  • 931
  • 7
  • 7

R, 8568 characters

s=sprintf;cat(s('%10s','*'),s('% *s%0*d',9:1,'',1:9*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.

R, 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.

R, 68 characters

s=sprintf;cat(s('%10s','*'),s('% *s%0*d',9:1,'',1:9*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.

Source Link
Tommy
  • 931
  • 7
  • 7

R, 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.