Output the legendary Yggdrasil

40

7

Your task is to output a representation of the legendary tree of life, Yggdrasil.

You must write a program whose output is exactly that :

                                       /\
                                      /**\
                                     /****\
                                    /******\
                                    /******\
                                   /********\
                                  /**********\
                                 /************\
                                /**************\
                                 /************\
                                /**************\
                               /****************\
                              /******************\
                             /********************\
                            /**********************\
                              /******************\
                             /********************\
                            /**********************\
                           /************************\
                          /**************************\
                         /****************************\
                        /******************************\
                           /************************\
                          /**************************\
                         /****************************\
                        /******************************\
                       /********************************\
                      /**********************************\
                     /************************************\
                    /**************************************\
                        /******************************\
                       /********************************\
                      /**********************************\
                     /************************************\
                    /**************************************\
                   /****************************************\
                  /******************************************\
                 /********************************************\
                /**********************************************\
                     /************************************\
                    /**************************************\
                   /****************************************\
                  /******************************************\
                 /********************************************\
                /**********************************************\
               /************************************************\
              /**************************************************\
             /****************************************************\
            /******************************************************\
                  /******************************************\
                 /********************************************\
                /**********************************************\
               /************************************************\
              /**************************************************\
             /****************************************************\
            /******************************************************\
           /********************************************************\
          /**********************************************************\
         /************************************************************\
        /**************************************************************\
               /************************************************\
              /**************************************************\
             /****************************************************\
            /******************************************************\
           /********************************************************\
          /**********************************************************\
         /************************************************************\
        /**************************************************************\
       /****************************************************************\
      /******************************************************************\
     /********************************************************************\
    /**********************************************************************\
            /******************************************************\
           /********************************************************\
          /**********************************************************\
         /************************************************************\
        /**************************************************************\
       /****************************************************************\
      /******************************************************************\
     /********************************************************************\
    /**********************************************************************\
   /************************************************************************\
  /**************************************************************************\
 /****************************************************************************\
/******************************************************************************\
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |--------|
                                   |________|

There is no trailing whitespace. The final newline may be omitted.

To make checking easier, here are the md5 sums of the expected output:

  • 374899e56bc854d04639c43120642e37 - No newline at end.
  • 03afb81d960b8e130fe2f9e0906f0482 - Newline at end

Standard loopholes apply. This is code-golf, so the smallest entry in bytes win!

user30395

Posted 2014-08-19T14:07:45.193

Reputation:

10

Related: http://codegolf.stackexchange.com/q/15860/15599 . Nax, you should work in marketing. Every household is going to want a Yggdrasil this Christmas. I see you answered the Graham's number question too. You must like pointy things. Let's have some new names for "rocket" and "ice cream cone."

– Level River St – 2014-08-19T14:18:33.420

Also related: http://codegolf.stackexchange.com/q/4244/194 .

– Peter Taylor – 2014-08-19T14:52:11.640

4@Nax: since the world tree has fruit, and angiosperms don't, and that is clearly a confiner of some description, unfortunately it looks like you took a picture of the wrong tree :P – naught101 – 2014-08-21T14:28:44.530

@Nax Hmm. You are correct. The pedant (me) is hoist on his own petard. The md5sums have changed. – Scott Leadley – 2014-08-22T13:52:16.367

1

Err, point of order, Yggdrasil is definitely an ash tree in the eddas, not a fir. Kinda like this.

– Alex P – 2014-08-22T15:06:07.850

Answers

22

Golfscript, 84 77 76 75 72 characters

Different approach from Howard's. Click on the character count to try it.

10,{.)4*,\3*>{.39\-' '*'/'@2*'*'*'\
'}/}/12,{' '35*'|'@11<'_-'1/=8*1$n}/

Thanks to Howard for saving 3 characters!

Explanation:

This is more or less a straightforward port of my Python solution. Taking some expressive liberties (using named variables instead of keeping track of stack positions, and print is really keeping things on the stack, not printing):

10,{...}/            # for i in range(10):
   .                 #    x = i
   )4*,              #    Y = range((i+1)*4)
   \3*               #    x *= 3
   >                 #    Y = Y[x:]  # y is now range(3*i, (i+1)*4)
   {...}/            #    for j in Y:
      .39\-          #        q = 39 - j
      ' '*           #        print ' '*q  # print right number of spaces
      '/'            #        print '/'
      @2*            #        j *= 2
      '*'*           #        print '*'*j
      '\<NEWLINE>'   #        print "\\\n"
12,{...}/            # for i in range(12):
    ' '35*           #    print ' '*35
    '|'              #    print '|'
    @11<             #    i = i < 11
    '_-'1/=          #    z = "_-"[i] # pick "-" if i < 11, else pick "_"
    8*               #    print z*8
    1$               #    print '|' # (copy from earlier in the stack)
    n                #    print "\n"

Claudiu

Posted 2014-08-19T14:07:45.193

Reputation: 3 870

1You may use the same line-break trick as in my solution. Instead of '\\'n pull the newline into the string (+/- 0 characters) and now the backslash no longer needs to be escaped (-1 character). – Howard – 2014-08-20T06:36:49.907

1Two more: 4*4+ is the same as )4* and '_-'[=] can be written '_-'1/= which makes the last + obsolete. – Howard – 2014-08-20T06:50:57.343

3an explanation could be useful...? is this too much to ask? – None – 2014-08-20T08:29:25.250

@professorfish: Coming right up! – Claudiu – 2014-08-20T15:46:16.880

Don't you need a trailing ';' here? Otherwise there will be two trailing newlines since golfscript by default adds one. – Nabb – 2014-08-24T03:48:31.403

21

Haml & Sass

37 + 277 = 314

Haml:

%link(rel="stylesheet" href="s")
%pre

Sass:

pre:after{$l:"";@for$k from0 to10{@for$i from0 to4+$k{@for$j from0 to40-($k*6+$i*2)/2{$l:$l+' ';}$l:$l+'/';@for$j from0 to$k*6+$i*2{$l:$l+'*';}$l:$l+"\\\a ";}}@for$i from0 to12{@for$j from0 to35{$l:$l+" ";}@if$i<11{$l:$l+"|--------|\a ";}@else{$l:$l+"|________|";}}content:$l;}

*Sass allows control directives, concatenation, and variable dereference. All of which are useful when styling, but verbose while golfing.


gets generated into:

HTML:

<link rel="stylesheet" href="s" /><pre></pre>

CSS:

pre:after {
  content: "                                        /\\\a                                        /**\\\a                                       /****\\\a                                      /******\\\a                                      /******\\\a                                     /********\\\a                                    /**********\\\a                                   /************\\\a                                  /**************\\\a                                   /************\\\a                                  /**************\\\a                                 /****************\\\a                                /******************\\\a                               /********************\\\a                              /**********************\\\a                                /******************\\\a                               /********************\\\a                              /**********************\\\a                             /************************\\\a               
             /**************************\\\a                           /****************************\\\a                          /******************************\\\a                             /************************\\\a                            /**************************\\\a                           /****************************\\\a                          /******************************\\\a                         /********************************\\\a                        /**********************************\\\a                       /************************************\\\a                      /**************************************\\\a                          /******************************\\\a                         /********************************\\\a                        /**********************************\\\a                       /************************************\\\a                      /**************************************\\\a                     /******************************
**********\\\a                    /******************************************\\\a                   /********************************************\\\a                  /**********************************************\\\a                       /************************************\\\a                      /**************************************\\\a                     /****************************************\\\a                    /******************************************\\\a                   /********************************************\\\a                  /**********************************************\\\a                 /************************************************\\\a                /**************************************************\\\a               /****************************************************\\\a              /******************************************************\\\a                    /******************************************\\\a                   /**********************************
**********\\\a                  /**********************************************\\\a                 /************************************************\\\a                /**************************************************\\\a               /****************************************************\\\a              /******************************************************\\\a             /********************************************************\\\a            /**********************************************************\\\a           /************************************************************\\\a          /**************************************************************\\\a                 /************************************************\\\a                /**************************************************\\\a               /****************************************************\\\a              /******************************************************\\\a             /*****************************************************
***\\\a            /**********************************************************\\\a           /************************************************************\\\a          /**************************************************************\\\a         /****************************************************************\\\a        /******************************************************************\\\a       /********************************************************************\\\a      /**********************************************************************\\\a              /******************************************************\\\a             /********************************************************\\\a            /**********************************************************\\\a           /************************************************************\\\a          /**************************************************************\\\a         /****************************************************************\\\a        /*********
*********************************************************\\\a       /********************************************************************\\\a      /**********************************************************************\\\a     /************************************************************************\\\a    /**************************************************************************\\\a   /****************************************************************************\\\a  /******************************************************************************\\\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    |--------|\a                                    
|--------|\a                                    |--------|\a                                    |________|"; }

the resulting page

Trevor Hickey

Posted 2014-08-19T14:07:45.193

Reputation: 341

1You don't see a ton of HTML/CSS solutions on CodeGolf. Nice job. – Mordred – 2014-08-20T20:02:15.843

16

CJam, 62 bytes

A,{I4+,{I3*J+_39\-S*'/@2*'**'\N}fJ}fI{35S*'|'-8*'|N++}C*'-/'_*

Try it online!

How it works

A,           " Push [ 0  …  9 ].                                                   ";
{            " For each I in that array:                                           ";
  I4+,       " Push [ 0  …  I + 3 ].                                               ";
  {          " For each J in that array:                                           ";
    I3*J+_   " Push K := 3 * I + J twice.                                          ";
    39\-S*   " Push a string consisting of 39 - K spaces.                          ";
    '/       " Push a slash.                                                       ";
    @2*'**   " Push a string consisting of 2 * K asterisks.                        ";
    '\N      " Push a backslash and a linefeed.                                    ";
  }fJ        "                                                                     ";
}fI          "                                                                     ";
{            " Do the following 12 times:                                          ";
  35S*       " Push a string consisting of 35 spaces.                              ";
  '|         " Push a vertical bar.                                                ";
  '-8*'|++   " Push the string '--------|\n'.                                      ";
}C*          "                                                                     ";
'-/'_*       " Replace the hyphen-minus signs of the last string with underscores. ";

Dennis

Posted 2014-08-19T14:07:45.193

Reputation: 196 637

Your Try it online. link only links to the blank interpreter without your source code. – Jonathan Frech – 2018-02-20T17:35:38.533

@JonathanFrech Yes, that was before the interpreter had permalinks. Fixed. – Dennis – 2018-02-20T18:13:09.117

2I've got to start using CJam instead of GolfScript... – Claudiu – 2014-08-20T16:10:06.217

What makes CJam code so compact? Is it just usual features match together well or there is some super-trick? Or it's actually not CJam, but CJam programmers so? – Vi. – 2014-08-21T01:40:44.503

2@Vi.: It's a mix of both. 1. CJam is stack based, so you usually get away without using any variables. 2. All built-ins' names are at most two characters long. Because of this, you don't need whitespace except for some special cases. 3. Even submissions in golfing languages don't golf themselves. My GolfScript/CJam programs are a lot shorter now than they used to be. – Dennis – 2014-08-21T03:29:34.937

Suggestion for CJam would be to use ASCII codes 128-256 for a whole nother set of built-ins. have some special editor that – Claudiu – 2014-08-21T19:36:13.907

@Claudiu: Well, that's up to its creator. If I designed my own golfing language, I think I would make it bit-based or encode all instructions arithmetically. – Dennis – 2014-08-21T23:30:48.600

15

GolfScript, 79 characters

10,{:^4+,{2*^6*+'*'*.,2/~40+' '*'/'@'\
'}/}/[' '35*]12*'|--------|
'*'||''_'8**

Try the code here. Note that the line breaks aren't optional in this code

Howard

Posted 2014-08-19T14:07:45.193

Reputation: 23 109

24A multi-line GolfScript solution? I didn't think I'd see the day! – Ingo Bürk – 2014-08-19T17:24:36.510

12

Python, 148 129 126 121 characters

R=range
for i in R(10):
 for j in R(i*3,4+i*4):print' '*(39-j)+'/'+'**'*j+'\\'
for c in'-'*11+'_':print' '*35+'|'+c*8+'|'

Thanks to Falko for saving 3 characters and to flornquake for brilliantly saving another 5!

Claudiu

Posted 2014-08-19T14:07:45.193

Reputation: 3 870

1Python's character multiplication is a bit too perfect for this challenge... – Sean Latham – 2014-08-19T15:24:54.637

Wait 'till you see my golfscript solution... =P – Claudiu – 2014-08-19T15:25:22.330

2Use '**'*j to save 3 characters. Apart from this my solution converges to the exact same code. :) – Falko – 2014-08-19T22:37:44.513

1You can make the last line shorter by writing for c in'-'*11+'_':print' '*35+'|'+c*8+'|'. – flornquake – 2014-08-21T08:54:01.820

@flornquake: nice! very clever – Claudiu – 2014-08-21T14:24:49.643

11

Bash, 236 197 193

10 bytes of code + 1-byte filename + 182-byte data file = 193 bytes total

zcat y 2>j

Explanation

y is a file containing the Yggdrasil, without a trailing new line, compressed with the zopfli algorithm (invoked as zopfli --i64) and then with the last 8 bytes removed. zopfli is compatible with gzip, so I can decompress the file with standard Bash utilities designed for gzip. The size of the data file is 182 bytes (229 bytes when normal gzip is used). The size of the original Yggdrasil, without the trailing new line, is 5876 bytes.

The removal of the last 8 bytes causes error messages, which are suppressed by sending standard error to a file called j. If j exists, it will be overwritten.

The base64 of y is (use base64 -d to obtain the original file):

H4sIAAAAAAACA+3SMQoCURDA0N5TWC+IFxK8yD/8Nul9hfDRnamT6J+du83zdUPwOACNNDb0+3Bs
tMPhSscDvusHgM9wIcUNclL+5r/luJXkmlh5rM3r8txkMdVNcEn1Nc2a1AU72XWz3Xd91r5z7eZD
AQKQgAI0PDFf8xJfExpQgQhkpAIdz8ytzK3AQMg6UMIQpLQELU/NQc5B/thBegtqHpOc16jHOX/v
x1mPZg19MfrdrBM=

And the md5sum is:

4a049a80241160cdde0a3cbca323b7f2

user16402

Posted 2014-08-19T14:07:45.193

Reputation:

2My finger was itching to hit the "delete" button when I saw the code, until I read the character count and explanation. :P – Doorknob – 2014-08-19T19:13:46.683

2You can save about 30 bytes by using zopfli to make the compressed file. "zopfli --i100 y" yields a 190-byte file that zcat can decompress. – Glenn Randers-Pehrson – 2014-08-19T22:44:30.497

1And a few more if you delete the last 10 bytes and close STDERR. – Dennis – 2014-08-19T23:57:39.537

@GlennRanders-Pehrson thanks for pointing this out, I've also edited my answer to 'Molar masses of compounds' http://codegolf.stackexchange.com/a/35613/16402 to use zopfli, saving 37 bytes

– None – 2014-08-20T08:26:59.243

@Dennis it turned out to be 8 bytes (any more and bits of the Yggdrasil's trunk would be missing), thanks – None – 2014-08-20T08:27:16.227

For me this is a totally fresh idea - yay! Much more interesting than the "standard" GolfScript solutions, clever though they are. – GreenAsJade – 2014-08-21T04:01:38.250

7

Ruby - 100

puts (0..21).map{|i|i>9??\ *35+?|+(i>20??_:?-)*8+?|:(0..i+3).map{|y|?\ *(39-z=y+3*i)+?/+?**z*2+?\\}}

Puts auto-flattens, so we can collect all the lines even in nested arrays. Needs Ruby 1.9

Try at ideone

Vectorized

Posted 2014-08-19T14:07:45.193

Reputation: 3 486

I think it needs some leading spaces. Also, works with Ruby 1.9, but not in 1.8. – Scott Leadley – 2014-08-19T18:28:13.760

7

C, 169

i;j;p(a,b){while(b--)putchar(a);}main(){for(;i++<10;)for(j=i*3-4;++j<i*4;p(32,39-j),p(47,1),p(42,j*2),puts("\\"));for(++i;i--;p(32,35),p(124,1),p(i?45:95,8),puts("|"));}

Ungolfed (and slightly disentangled):

int i;
int j;
void p(a,b) {
  while (b--) putchar(a);
}
void main() {
  for (;i++<10;) {
    for (j=i*3-4;++j<i*4;) {
      p(32,39-j);
      p(47,1);
      p(42,j*2);
      puts("\\");
    }
  }
  for (++i;i--;) {
    p(32,35);
    p(124,1);
    p(i?45:95,8);
    puts("|");
  }
}

r3mainer

Posted 2014-08-19T14:07:45.193

Reputation: 19 135

7

PowerShell 104 101

0..9|%{(3*$_)..(3+$_*4)|%{" "*(39-$_)+"/"+"*"*2*$_+"\"}};0..11|%{" "*35+"|"+("-","_")[$_-eq11]*8+"|"}

DarkAjax

Posted 2014-08-19T14:07:45.193

Reputation: 669

6

C# 258 234bytes

Thanks to some annoymous user for the suggested edits making good use of the String.PadLeft method!

using System;class G{static void Main(){Action<string>p=Console.WriteLine;int i=0,j;for(;i++<10;)for(j=i*3-3;j++<i*4;)p("/".PadLeft(41-j)+"\\".PadLeft(2*j-1,'*'));while(i-->0)p("|--------|".PadLeft(45));p("|________|".PadLeft(45));}}

The code is pretty simple, not much left to golf.

Formatted code:

using System;
class G
{
    static void Main()
    {
        Action<string> p = Console.WriteLine;
        int i = 0, j;
        for(; i++ < 10 ;)
            for(j = i*3 - 3; j++ < i*4;)
                p("/".PadLeft(41 - j) + "\\".PadLeft(2*j - 1,'*'));
        while(i-- > 0)
            p("|--------|".PadLeft(45));
        p("|________|".PadLeft(45));
    }
}

VisualMelon

Posted 2014-08-19T14:07:45.193

Reputation: 3 810

Using \r is pointless here. This is code golf. – nyuszika7h – 2014-08-19T15:56:56.977

3@nyuszika7h indeed, but it's included in the formatted copy for good measure so that people using notepad can more easily see the glory of the Yggdrasil (it's not included in the score) – VisualMelon – 2014-08-19T16:06:58.820

Oh, I see. Windows... Feel free to fix my edit then. – nyuszika7h – 2014-08-19T16:07:35.847

@nyuszika7h thanks for pointing out the Syntax Highlighting wasn't right – VisualMelon – 2014-08-19T16:10:10.047

6

J, 98 88 84 75

(85 11 1#3 4$' /*\ |-| |_|')#"1~(39&-,1,+:,1:)"0(12$4),~85(-4&+#-:*>:)&i.10

FireFly

Posted 2014-08-19T14:07:45.193

Reputation: 7 107

4

Ruby - 139 129 126 123 121

Hoisted "puts" outside of array creation (suggestion from bitpwner).

puts (0..9).map{|i|(i*3...(i+1)*4).map{|j|"/#{'**'*j}\\".rjust(41+j,' ')}}+["%45s"%'|--------|']*11<<'%45s'%'|________|'


Ungolfed ("puts" unhoisted):


# print fill patterns from the intervals
# [0..3, 3..7, 6..11, 9..15, 12..19, 15..23, 18..27, 21..31, 24..35, 27..39]
# centered on columns 81-82
(0..9).each { |i|
  (i*3...(i+1)*4).each { |j|    # x...y vs x..y-1 saves a char
    puts "/#{'**'*j}\\".rjust(41+j,' ')
  }
}
# print the stump
puts ("%45s\n" % '|--------|') * 11
puts '%45s' % '|________|'

Scott Leadley

Posted 2014-08-19T14:07:45.193

Reputation: 459

@bitpwner I think this deserves it's own answer. Go for it. – Scott Leadley – 2014-08-19T16:58:09.270

4

Perl, 127

for$i(0..9){for$j($i*3..3+$i*4){print" "x(39-$j),"/","*"x($j*2),"\\\n";}}for$i(0..11){print" "x35,"|",($i>10?"_":"-")x8,"|\n";}

Ungolfed:

for $i (0..9) {
  for $j ($i*3..3+$i*4) {
    print " "x(39-$j) , "/" , "*"x($j*2) , "\\\n";
  }
}
for $i (0..11) {
  print " "x35 , "|" , ($i>10?"_":"-")x8 , "|\n";
}

r3mainer

Posted 2014-08-19T14:07:45.193

Reputation: 19 135

Replace $i with $_ and save 4 characters. – choroba – 2014-08-24T17:09:20.147

4

PHP 223 202 181 160 156

Edit I figured out how to alias a function with a variable and was able to chop off some more characters. That str_repeat function was really verbose

Edit 2: Thanks everyone for the suggestions!

Golfed:

<?$s=str_repeat;for($i=-1;$i++<9;)for($j=$i*3;$j<4+$i*4;)echo$s(' ',39-$j).'/'.$s('**',$j++)."\\
";for($i=12;$i--;)echo$s(' ',35),'|'.$s($i?'-':'_',8)."|
";

Readable:

    <?

$s=str_repeat;

for($i=-1;$i++<9;)
{
    for($j=$i*3;$j<4+$i*4;)
    {
        echo$s(' ',39-$j).'/'.$s('**',$j++)."\\
        ";
    }
}

for($i=12;$i--;)
{
    echo$s(' ',35),'|'.$s($i?'-':'_',8)."|
    ";
}

Output: http://brobin.me/yggdrasil.php

Brobin

Posted 2014-08-19T14:07:45.193

Reputation: 201

You can remove $i=0 if you use the -n flag. And a general hint: using str_pad is almost always shorter than str_repeat. – Titus – 2018-03-27T00:48:57.567

You can save 6 chars by removing parenthesis around (39-$j), ($j*2) and ($i==11). -2 by replacing \n with real new line characters (PHP allows it in litterals). -5 chars by replacing (both) for($i=0;$i<12;$i++) with for($i=12;$i-->0;) and $i==11 with $i==0. – sebcap26 – 2014-08-21T10:56:02.103

After that you can also replace $s(($i==0?'_':'-'),8) with $s($i?'-':'_',8). (==> -5 chars) – sebcap26 – 2014-08-21T11:04:47.897

-1 Character by replacing $s('*',$j*2) with $s('**',$j). I think that's the last improvement that I can find. – sebcap26 – 2014-08-21T11:44:09.053

-2 changing ($j*2) in inner for to ($j++*2) and removing $j++ from for() arguments – avall – 2014-08-21T12:47:17.210

@sebcap26 for($i=12;$i-->0;) can be shortened to for($i=12;$i--;) - another 2 chars. – avall – 2014-08-21T13:23:12.543

@avall Nice ! I made a fiddle With all our modifications (I'm not sure if we should edit the answer) : http://jsfiddle.net/ckqhqxh1/

– sebcap26 – 2014-08-21T13:41:32.097

I just made the edits. Thanks everyone for your sugggestions! Chopped 19 characters off. – Brobin – 2014-08-21T13:48:42.067

2 errors: swap '_':'-' to '-':'_' and write $j++ in second use of $j, not first. – avall – 2014-08-21T13:58:43.717

-2 for changing for($i=0;$i<10;$i++) to for($i=-1;$i++<9;) – avall – 2014-08-21T14:09:20.270

-2 for changing first characters to $s=str_repeat, and -1 for removing \n and simply pressing an enter there. – Vlad Preda – 2014-08-22T08:38:45.133

3

Javascript, 288 281

Chrome hides duplicated console.logs, use IE instead.

function t(w){s="";for(i=0;i++<39-w;)s+=" ";s+="/";for(i=0;i++<w*2;)s+="*";return s+"\\"}function r(l){s="";for(i=0;i++<36;)s+=" ";s+="|";for(i=0;i++<8;)s+=l;return s+"|"}w=0;c=console;for(h=0;h++<10;){for(j=0;j++<3+h;)c.log(t(w++));w-=h}for(j=0;j++<11;)c.log(r('-'));c.log(r('_'))

Ungolfed:

function t(w)
{
    s="";
    for(i=0;i++<39-w;)
        s+=" ";
    s+="/";
    for(i=0;i++<w*2;)
        s+="*";
    return s+"\\"
}
function r(l)
{
    s="";
    for(i=0;i++<36;)
        s+=" ";
    s+="|";
    for(i=0;i++<8;)
        s+=l;
    return s+"|"
}

w=0;
c=console;
for(h=0;h++<10;)
{
    for(j=0;j++<3+h;)
        c.log(t(w++));
    w-=h;
}
for(j=0;j++<11;)
    c.log(r('-'));
c.log(r('_'))

Sean Latham

Posted 2014-08-19T14:07:45.193

Reputation: 1 423

Use for(i=0;i++<39-w;) instead of for(i=0;i<39-w;++i), and so on. Also, p=console.log instead of c=console and p instead of c.log (although I only tested the latter in Node.js, it doesn't work in Firefox). This saves 12 bytes. – nyuszika7h – 2014-08-19T16:10:08.360

c=console.log didn't work in Chrome either, so I didn't use it. The for loop tricks save 7 bytes though. – Sean Latham – 2014-08-19T16:33:09.257

I'm usually quite wary of anything encouraging me to use MSIE... – None – 2014-08-19T17:45:02.747

This is quite possibly the first time I've ever seen the phrase "use IE instead." O_o However, you can suppress Chrome's behavior by simply running this code in the console instead of from a webpage. – Doorknob – 2014-08-19T19:17:37.423

Running it in a page and in the console produces the same results for me on both Firefox and Chrome. – Sean Latham – 2014-08-19T20:05:19.027

3

Delphi 429

Will try to improve later.
Golfed

uses strutils,SysUtils,Classes;const a='|----';b='|____';c:array [0..9,0..1]of int32=((0,3),(3,7),(6,11),(9,15),(12,19),(15,23),(18,27),(21,31),(24,35),(27,39));var t:TStrings;i,j:integer;begin t:=tstringlist.Create;for I:=0to 9do for J:=c[i,0]to c[i,1]do t.Add('/'+StringOfChar('*',j));for I:=0to 10do t.Add(a);t.Add(b);for I:=0to t.Count-1do t[i]:=t[i].PadLeft(40)+ReverseString(t[i]).Replace('/','\');write(T.TEXT);readln;end.

ungolfed

uses
  strutils,SysUtils,Classes;
const
  a='|----';
  b='|____';
  c:array [0..9,0..1]of int32=((0,3),(3,7),(6,11),(9,15),(12,19),(15,23),(18,27),(21,31),(24,35),(27,39));
var
  t:TStrings;
  i,j:integer;
begin
  t:=tstringlist.Create;
  for I:=0to 9do
    for J:=c[i,0]to c[i,1]do
      t.Add('/'+StringOfChar('*',j));
  for I:=0to 10do
    t.Add(a);
  t.Add(b);
  for I:=0to t.Count-1do
    t[i]:=t[i].PadLeft(40)+ReverseString(t[i]).Replace('/','\');
  write(T.TEXT);
  readln;
end.

Teun Pronk

Posted 2014-08-19T14:07:45.193

Reputation: 2 599

3

C (219)

Thanks to everyone for the golfing tips -- managed to get it down to 219. Don't think it'll go much lower.

w,W,s,S,i,r;main(){char T[78];memset(T,42,78);for(r=4,s=39;r<14;++r,s-=3,w+=6)for(i=0,S=s,W=w;i<r;++i,W+=2,--S)printf("%*s/%.*s\\\n",S,"",W,T);for(i=0;i<11;i++)printf("%35s|--------|\n","");printf("%35s|________|","");}

Required includes:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

DreamWarrior

Posted 2014-08-19T14:07:45.193

Reputation: 571

If he's willing to use C89 he can omit all the includes as well. There is no case in this code where implicit declaration on call screws up. – Joshua – 2014-08-19T15:24:21.403

@Nax; that gets me to 263 -- and I pulled includes out. Thanks. – DreamWarrior – 2014-08-19T15:24:51.663

@Joshua -- 64 bit systems and memset could be problematic, but...otherwise, maybe not. Either way, most people remove the includes, so I did, too. – DreamWarrior – 2014-08-19T15:26:03.903

It's actually 262 characters, you don't need the trailing newline. – nyuszika7h – 2014-08-19T15:49:25.813

You can use 32 instead of ' ' and 42 instead of '*' :) – Quentin – 2014-08-19T18:46:33.410

s/w2/b, s/s2/c . – djechlin – 2014-08-20T17:50:12.320

Quick suggestions: global implicit ints, drop S, use int for space and asterisk for 228 bytes. w,w2,s2,i;main(){int r=4,s=39;char T[78];memset(T,42,78);for(;r<14;++r,s-=3,w+=6)for(i=0,s2=s,w2=w;i<r;++i,w2+=2,--s2)printf("%*s/%.*s\\\n",s2,"",w2,T);for(i=0;i<11;i++)printf("%35s|--------|\n","");printf("%35s|________|","");} – None – 2014-08-20T20:56:54.283

Thanks y'all...I'll keep these in mind for future golfs. Somehow I just have issues writing golf'd code; I guess keeping code quasi-readable has been pounded in me too hard, lol. – DreamWarrior – 2014-08-21T15:32:20.780

3

JavaScript (console.log), 168 166

(Whitespace for readability only)

for(i=c=0;i<11;i++)
  for(j=0;j<4+i&!c;j++)
    l=i*13+j,
    a=Array(n=i-10?3*i+j+1:5).join("*-_"[k=(l>129)+(c=l==141)]),
    console.log(Array(41-n).join(" ")+'/||'[k]+a+a+'\\||'[k])

FireFly

Posted 2014-08-19T14:07:45.193

Reputation: 7 107

3

Haskell, 153 148

Straight-forward, no tricks, just plain golfing:

(a:b:c)%n=(39-n)&' '++a:(2*n)&b++c
n#m=[n..m]++(n+3)#(m+4)
(&)=replicate
main=putStr$unlines$map("/*\\"%)(take 85$0#3)++map("|-|"%)(11&4)++["|_|"%4]

The % operator draws a single line, its first argument being a String of length 3 containing the borders and the fill characters in that line (now assuming exactly 3 Chars, saving 5 bytes), the second, an Int, specifies half the number of fill characters. Pattern matching, cons-ing and appending is used in combination in order to save bytes by taking care of the "glue" between Char and String. In this second version, I also made # infinite and introduced a take 85 to make it finite again (no bytes saved, unfortunately).

The # operator creates the sequence for the n argument to % required for the tree: [0..3], [3..7], ... concatenated.

& is just an infix shorthand for replicate, which occurs three times.

The tree is put together in the last line, the newlines are added by unlines.

TheSpanishInquisition

Posted 2014-08-19T14:07:45.193

Reputation: 421

138 bytes – Max Yekhlakov – 2019-04-05T06:32:34.973

2

Pyth, 101 100 99 90 81 bytes

J0Km/*+d7d2S9V85FTKI!-TN=hZ=+JZ))+*d-39-NJ++\/*"**"-NJ\\)Va*]\-11\_+++*d35\|*N8\|

Try it online!

Python 3 translation:
Z=0
d=" "
J=0
K=list(map(lambda d:((d+7)*d)//2,range(1,10)))
for N in range(85):
    for T in K:
        if not T-N:
            Z+=1
            J+=Z
    print(d*(39-(N-J))+"/"+"**"*(N-J)+"\\")
for N in ["-"]*11+["_"]:
    print(d*35+"|"+N*8+"|")

hakr14

Posted 2014-08-19T14:07:45.193

Reputation: 1 295

Isn't the a function defined in your Python equivalent to + on lists? – Esolanging Fruit – 2018-02-20T01:34:49.587

@EsolangingFruit It's close, but not exactly: <list>+<str> is not a valid operation, but I could just as easily use ["-"]*11+["_"]. I decided to define my own function to more accurately translate what Pyth is actually doing. – hakr14 – 2018-02-20T17:24:18.730

Okay, that makes sense. – Esolanging Fruit – 2018-02-21T04:29:14.823

2

Powershell, 88 bytes

0..9|%{(3*$_)..(3+$_*4)|%{' '*(39-$_)+"/$('**'*$_)\"}}
,'-'*10+'_'|%{' '*35+"|$($_*8)|"}

mazzy

Posted 2014-08-19T14:07:45.193

Reputation: 4 832

2

Lua - 164

a=' 'for i=0,9 do for j=i*3,3+i*4 do print(a:rep(39-j)..'/'..(('*'):rep(j*2))..'\\')end end for i=0,11 do print(a:rep(35)..'|'..((i>10 and'_'or'-'):rep(8))..'|')end

Adriweb

Posted 2014-08-19T14:07:45.193

Reputation: 333

2

Mathematica 191 178

For sure not the best solution:

n=Nest;
t=Table;
""<>
    t[
        {n[#<>" "&,"",39-i],"/",n[#<>"*"&,"",2i],"\\\n"}
    ,
        {i,Flatten@t[Range[j+4]-1+3j,{j,0,9}]}
    ]
<>
    t[
        n[#<>" "&,"",35]<>If[i==12,"|________|\n","|--------|\n"]
    ,
        {i,12}
    ]

Not counting newlines. Mathematica skews the output, as it doesn't take the same width for a whitespace as for "*" and "/". But the result is correct.

freddieknets

Posted 2014-08-19T14:07:45.193

Reputation: 199

(it's my first golf) – freddieknets – 2014-08-21T03:09:35.437

2

Java - 286

My first golf.

Golfed:

class M{public static void main(String[]args){int i=0,a,f=0;String s="";for(;i++<11;){for(a=i*3-4;++a<i*4;){if(i>10){a=4;if(++f>12)break;}s+=s.format("%"+(40-a)+"s"+(a>0?"%0"+a+"d":"")+"%3$s",f>0?"|":"/",0,f>0?"|":"\\").replace("0",f<1?"**":f>11?"__":"--")+"\n";}}System.out.println(s);}}

Ungolfed:

class M {
    public static void main(String[] args) {
        int i=0,a,f=0;
        String s = "";
        for(;i++<11;){
            for(a=i*3-4;++a<i*4;a++){
                if(i>10){
                    a=4;
                    if(++f>12)break;
                }
                s+=s.format("%"+(40-a)+"s"+(a>0?"%0"+a+"d":"")+"%3$s",f>0?"|":"/", 0,f>0?"|":"\\").replace("0", f<1?"**":f>11?"__":"--")+"\n";
            }
        }
        System.out.println(s);
    }
}

Test here

LudziE12

Posted 2014-08-19T14:07:45.193

Reputation: 21

2

Python 2, 117

j=0
while j<40:j-=j/4;exec(j/3+4)*r"print' '*(39-j)+'/'+'**'*j+'\\';j+=1;"
for c in'-'*11+'_':print' '*35+'|'+c*8+'|'

Other versions I tried include:

# 118
for i in range(10):j=i*3;exec(i+4)*r"print' '*(39-j)+'/'+'**'*j+'\\';j+=1;"
for c in'-'*11+'_':print' '*35+'|'+c*8+'|'

# 118
i=j=4
while j:j=52-3*i;exec"j-=1;print' '*j+'/'+'**'*(39-j)+'\\\\';"*i;i+=1
for c in'-'*11+'_':print' '*35+'|'+c*8+'|'

# 118
j=0
for b in'\\'*10:j-=j/4;exec(j/3+4)*"print' '*(39-j)+'/'+'**'*j+b;j+=1;"
for c in'-'*11+'_':print' '*35+'|'+c*8+'|'

# 119
s=40
while s:s+=10-s/4;exec(52-s)/3*r"s-=1;print' '*s+'/'+'**'*(39-s)+'\\';"
for c in'-'*11+'_':print' '*35+'|'+c*8+'|'

flornquake

Posted 2014-08-19T14:07:45.193

Reputation: 1 467

1

Assembly (MIPS, SPIM), 768 671 659 655 654 bytes

.text
.globl main
main:
li $8 32
li $9 47
li $t2 42
li $t3 92
li $t4 10
li $t5 42
addi $sp -4
move $4 $sp
la $s6 q
la $s5 w
li $t8 0
li $s0 10
li $t9 0
li $s3 40
li $s2 39
q:
sub $s3 $s3 $t8
add $s2 $s2 $t8
addi $t7 $t8 3
addi $t8 1
blt $s0 $t8 e
r:
sw $0 ($4)
blt $t9 $s2 t
beq $t9 $s2 y
beq $t9 $s3 u
beqz $t7 i
sb $t2 ($4)
p:
li $2 4
syscall
addi $t9 1
ble $t9 $s3 r
move $t9 $0
j $s5
o:
addi $t7 -1
bgez $t7 r
jr $s6
w:
addi $s2 -1
addi $s3 1
j o
t:
sb $8 ($4)
j p
y:
sb $9 ($4)
j p
u:
sb $t4 1($4)
sb $t3 ($4)
j p
i:
sb $t5 ($4)
j p
e:
li $t1 124
li $t3 124
li $t2 45
li $t5 95
li $t7 11
la $s6 a
la $s5 o
li $s2 35
li $s3 44
j r
a:
li $2 10
syscall

Try it online!

Edit: Saved ~100 bytes by hard coding each character in a register and simply writing to the stack, then abusing the fact that MIPS doesn't have types so implicit word to ascii string is allowed.
Edit 2: removed duplicate stack alloc. (addi $sp -4) Oops!
Edit 3: in rewrite, accidently made the tree stump 1 character too short. (36 in stead of 35). Fixed.
Edit 4: -4 bytes by using $8 and $9 instead of $t0 and $t1. they mean the same thing, but $t0 is easier to read. unfortunately, all other t registers are the same length when written nicely ($t2 == $10, but both are 3 characters), so the rest are a wash. I could (in theory) use the remaining 'a' registers (5-7. print syscall uses 4), but afaik the behavior isn't defined when using syscall.
-1 Byte by setting t8 to 0 and branching on less than instead of on equal. also required me to reorder the add ops, which unfortunately made the execution time take a whopping 3 opcodes longer.

Not the best at MIPS, but after clearing my conscience of this in meta discussion, i'm submitting them. MIPS is not designed for this (no output, no for loops) but it's pretty fun to do this perhaps in spite of that.

Unfortunately, I haven't created a commented version for this new solution, but you can view the old version, with full documentation here

Feel free to take the credit and improve upon this answer if you can beat it - I'm probably missing a few optimizations here and there.

Andrew Baumher

Posted 2014-08-19T14:07:45.193

Reputation: 351

since this solution doesn't require .data, it's possible to convert to binary (compiled) and save a bunch of bytes. however, SPIM doesn't support it, so c'est la vie. – Andrew Baumher – 2019-09-04T00:29:04.970

Also, I'm not sure if the shorthand addi $sp -4 which is really addi $sp $sp -4 is from SPIM or MIPS in general, so if anyone else does, please let me know. – Andrew Baumher – 2019-09-04T01:16:50.137

1

Groovy 118

10.times{(it*3).upto 3+it*4,{println' '*(39-it)+'/'+'*'*it*2+'\\'}};12.times{println' '*35+'|'+(it>10?'_':'-')*8+'|'}

cfrick

Posted 2014-08-19T14:07:45.193

Reputation: 313

1Why am I not surprised to see a pretty short Groovy solution. My impression of Groovy was that it was done by a Java programmer who hated typing. – Almo – 2014-08-21T13:38:19.523

1

C,194

This code is a hot mess and can definitely be golfed more. Still, it was an opportunity to try out a couple of things I've never done before: using a literal for a string of asterisks, and using the width specifier * with a string in printf.

i,j=5,k=5,n;
main(){
  char d[]={[0 ...77]=42,0};
  for(;i<85;i++)k--,j+=!k,k+=(j-1)*!k,n=39-i+(j-5)*(j-4)/2,printf("%*s/%s\\\n",n,"",d+n*2);
  for(;i<97;i++)printf("%*s|\n",44,i-96?"|--------":"|________");
}

Level River St

Posted 2014-08-19T14:07:45.193

Reputation: 22 049

1

Racket 223 220 211 204 198

Golfed:

(for-each display(flatten(let([m make-list])`(,(for*/list([i 10][j(range(* i 3)(* 4(+ 1 i)))])`(,(m(- 39 j)" ")"/",(m j"**")"\\\n")),(for/list([c`(,@(m 11"-")"_")])`(,(m 35" ")"|",(m 8 c)"|\n"))))))

Ungolfed:

(for-each display
     (flatten
      (let([m make-list])
        `(,(for*/list([i 10][j(range(* i 3)(* 4(+ 1 i)))])
             `(,(m(- 39 j)" ")"/",(m j"**")"\\\n"))
          ,(for/list([c`(,@(m 11"-")"_")])
             `(,(m 35" ")"|",(m 8 c)"|\n"))))))

Matthew Butterick

Posted 2014-08-19T14:07:45.193

Reputation: 401

0

C (gcc), 163 160 159 bytes

-3 -1 bytes thanks to ceilingcat.

j,w,s[99];main(i){for(;++i<12;w-=i-1)for(j=i+2;j--;)printf("%*c%.*s\\\n",40-w++,47,w*2,memset(s,42,99));for(;i--;)printf("%44s|\n",i?"|--------":"|________");}

Try it online!

gastropner

Posted 2014-08-19T14:07:45.193

Reputation: 3 264

Is limiting the number of printed string characters by using "%.*s" in a printf call standard behaviour? – Jonathan Frech – 2018-02-20T17:42:46.997

@JonathanFrech Yep, should be. "If the precision is specified, no more than that many bytes are written." - §7.21.6.1 of this document. (It regards fprintf, but the section on printf states that the format string works the same way as for fprintf.)

– gastropner – 2018-02-21T00:51:49.613

0

Jelly, 56 bytes

4Ḷ4ịr+L}¥¥Ɗ9СẎḤ”*ẋ⁾/\jЀ;⁾-_x11,1¤ẋ8⁾||jƊ€¤µLH40_⁶ẋ;µ€Y

Try it online!

Erik the Outgolfer

Posted 2014-08-19T14:07:45.193

Reputation: 38 134

0

PHP, 140 138 136 bytes

while($n--||30>$w+=3-$n=3+$i++)echo($p=str_pad)("",39-$w),$p("/",1|2*$w++,"*"),"\\
";while(-~$i)echo$p("",35),$p("|",9,$i--?"-":_),"|
";

less golfed:

for(;$i<10;$w-=$i)for($n=3+$i++;$n--;)
    echo str_pad("",39-$w), str_pad("/",1+2*$w++,"*"),"\\\n";
for($i++;$i--;)
    echo str_pad("",35), str_pad("|",9,$i?"-":_),"|\n";

Run with php -nr '<code>' or try it online. Requires PHP 7.

Titus

Posted 2014-08-19T14:07:45.193

Reputation: 13 814

0

Japt -R, 51 50 49 48 bytes

Ao*3 cÈôY+3@'\i'/+Xç*²
cCÆ'|i|+8ç"-_"gXzB})û mx1

Test it

Ao*3 cÈôY+3@'\i'/+Xç*²
A                             :10
 o                            :Range [0,A)
  *3                          :Multuply each by 3
     c                        :Flatten after ...
      È                       :  Map each X at 0-based index Y
       ôY+3                   :    Sorted range [X,X+Y+3]
           @                  :    Map each X
            '\i               :      Prepend "\" with
               '/+            :        "/" appended with
                  Xç          :          X times repeat
                    *²        :            "*" repeated twice
cCÆ'|i|+8ç"-_"gXzB})û mx1
c                             :Concatenate
 C                            :  12
  Æ                           :  Map each X in the range [0,C)
   '|i                        :    Prepend "|" with
      |+                      :      "|" appended with
        8ç                    :        8 times repeat
          "-_"g               :          Get the character in "-_" at index
               Xz             :            X floor divided by
                 B            :              11
                  }           :  End map
                   )          :End concat
                    û         :Centre pad each element with spaces to the length of the longest
                      m       :Map
                       x1     :  Trim right
                              :Implicit output, joined with newlines

Shaggy

Posted 2014-08-19T14:07:45.193

Reputation: 24 623

0

05AB1E, 36 bytes

TLεÌÝN3*+'*×'/ì]˜…|--11и…|__ªº€¨«º.c

Try it online!

TLε            ]       # for y in [1 .. 10]
   ÌÝ                  #  [0 .. y+2]
     N                 #  0-based iteration count (effectively y-1)
      3*               #  times 3
        +              #  add (vectorizes over the range, yielding [3*y-3 .. 4*y-1])
         '*×           #  "*" repeated that many times (vectorizes)
            '/ì        #  prepend "/" (vectorizes)
˜                      # flatten
 …|--                  # literal "|--"
     11и               # repeated 11 times as an array
        …|__           # literal "|__"
            ª          # appended to that array
             º         # mirror (vectorizes: ["|----|", "|----|", ..., "|____|")
              ۬       # remove the last character of each
                «      # merge the two lists (["/", "/*", ..., "|----", ...])
                 º     # mirror
                  .c   # center

Grimmy

Posted 2014-08-19T14:07:45.193

Reputation: 12 521

0

Canvas, 40 bytes

A{3+{╷¹╷3×+*×/×}]⁵-*_∔{4×|×]∔{║L»‾◂∔ ××]

Try it here!

dzaima

Posted 2014-08-19T14:07:45.193

Reputation: 19 048

0

Cobra - 166 228 260

class P
    def main
        for x in 10,for n in 4+x,print' '.repeat(39-x*3-n)+'/['**'.repeat(x*3+n)]\\'
        w=' '.repeat(35)
        print'[w]|--------|\n'.repeat(11)+w+'|________|'

Οurous

Posted 2014-08-19T14:07:45.193

Reputation: 7 916

0

Python (313)

'eJztmEsOwjAMBfecoutIFUfiIjk8FAJNE3+eE0sI6qxnRq3jVZYFOlcQSwnlMPIJeqOFRNgPCsAVq9MH+Lvxhtb4DlcEgpcNUvjBr2IMyWEVQRIc3hKlk/2VYnGeqjEi4NEmJMZwrCpoUi6sErLB7W2THKPGXe9RG+3WN+tNYMA/FoYCcX9/dH+DhboxnKgiE429MhWJ3egSsRttZrLy7kxnSsih8yq5hGL9+Eqsn1TyWz+n0tZySz1ijq2UXGPQi1pey8mXoM9F38rJd5RXZaM='.decode('base64').decode('zip')

ɐɔıʇǝɥʇuʎs

Posted 2014-08-19T14:07:45.193

Reputation: 4 449

Doesn't output anything. With print,the backslashes and linefeeds seem to be missing. – Dennis – 2014-08-22T17:21:44.453