Sortie du légendaire Yggdrasil

39

Votre tâche consiste à produire une représentation du légendaire arbre de la vie, Yggdrasil .

Vous devez écrire un programme dont le résultat est exactement celui-là:

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

Il n'y a pas d'espaces de fuite. La nouvelle ligne finale peut être omise.

Pour faciliter la vérification, voici les sommes md5 de la sortie attendue:

  • 374899e56bc854d04639c43120642e37 - Pas de nouvelle ligne à la fin.
  • 03afb81d960b8e130fe2f9e0906f0482 - Newline à la fin

Les failles standard s'appliquent. C'est du code-golf, donc la plus petite entrée en octets est gagnante!

caird coinheringaahing
la source
10
Connexe: codegolf.stackexchange.com/q/15860/15599 . Nax, tu devrais travailler dans le marketing. Chaque ménage voudra un Yggdrasil ce Noël. Je vois que vous avez également répondu à la question sur le numéro de Graham. Vous devez aimer les choses pointues. Ayons de nouveaux noms pour "rocket" et "cornet de crème glacée".
Level River St
Également lié: codegolf.stackexchange.com/q/4244/194 .
Peter Taylor
4
@ Nax: comme l'arbre du monde a des fruits, pas les angiospermes, et c'est clairement un confineur d'une description quelconque, malheureusement, il semblerait que vous ayez pris une photo du mauvais arbre: P
naught101
@Nax Hmm. Vous avez raison. Le pédant (moi) se hisse sur son propre pétard. Les sommes md5 ont changé.
Scott Leadley
1
Euh, rappel au Règlement, Yggdrasil est définitivement un frêne dans les eddas, pas un sapin. Un peu comme ça .
Alex P

Réponses:

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
la source
1
You 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
1
Two more: 4*4+ is the same as )4* and '_-'[=] can be written '_-'1/= which makes the last + obsolete.
Howard
3
an explanation could be useful...? is this too much to ask?
@professorfish: Coming right up!
Claudiu
Don't you need a trailing ';' here? Otherwise there will be two trailing newlines since golfscript by default adds one.
Nabb
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
la source
1
You don't see a ton of HTML/CSS solutions on CodeGolf. Nice job.
Mordred
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
la source
2
I've got to start using CJam instead of GolfScript...
Claudiu
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.
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
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
@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
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
la source
24
A multi-line GolfScript solution? I didn't think I'd see the day!
Ingo Bürk
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
la source
1
Python's character multiplication is a bit too perfect for this challenge...
Sean Latham
Wait 'till you see my golfscript solution... =P
Claudiu
2
Use '**'*j to save 3 characters. Apart from this my solution converges to the exact same code. :)
Falko
1
You can make the last line shorter by writing for c in'-'*11+'_':print' '*35+'|'+c*8+'|'.
flornquake
@flornquake: nice! very clever
Claudiu
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

la source
2
My finger was itching to hit the "delete" button when I saw the code, until I read the character count and explanation. :P
Doorknob
2
You 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
1
And a few more if you delete the last 10 bytes and close STDERR.
Dennis
@GlennRanders-Pehrson thanks for pointing this out, I've also edited my answer to 'Molar masses of compounds' codegolf.stackexchange.com/a/35613/16402 to use zopfli, saving 37 bytes
@Dennis it turned out to be 8 bytes (any more and bits of the Yggdrasil's trunk would be missing), thanks
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("|");
  }
}
squeamish ossifrage
la source
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
la source
I think it needs some leading spaces. Also, works with Ruby 1.9, but not in 1.8.
Scott Leadley
7

PowerShell 104 101

0..9|%{(3*$_)..(3+$_*4)|%{" "*(39-$_)+"/"+"*"*2*$_+"\"}};0..11|%{" "*35+"|"+("-","_")[$_-eq11]*8+"|"}
DarkAjax
la source
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
la source
Using \r is pointless here. This is code golf.
nyuszika7h
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
Oh, I see. Windows... Feel free to fix my edit then.
nyuszika7h
@nyuszika7h thanks for pointing out the Syntax Highlighting wasn't right
VisualMelon
6

J, 98 88 84 75

(85 11 1#3 4$' /*\ |-| |_|')#"1~(39&-,1,+:,1:)"0(12$4),~85(-4&+#-:*>:)&i.10
FireFly
la source
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";
}
squeamish ossifrage
la source
Replace $i with $_ and save 4 characters.
choroba
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
la source
@bitpwner I think this deserves it's own answer. Go for it.
Scott Leadley
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
la source
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
After that you can also replace $s(($i==0?'_':'-'),8) with $s($i?'-':'_',8). (==> -5 chars)
sebcap26
-1 Character by replacing $s('*',$j*2) with $s('**',$j). I think that's the last improvement that I can find.
sebcap26
-2 changing ($j*2) in inner for to ($j++*2) and removing $j++ from for() arguments
avall
@sebcap26 for($i=12;$i-->0;) can be shortened to for($i=12;$i--;) - another 2 chars.
avall
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
la source
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
la source
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
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
I'm usually quite wary of anything encouraging me to use MSIE...
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
Running it in a page and in the console produces the same results for me on both Firefox and Chrome.
Sean Latham
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
la source
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
la source
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
@Nax; that gets me to 263 -- and I pulled includes out. Thanks.
DreamWarrior
@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
It's actually 262 characters, you don't need the trailing newline.
nyuszika7h
You can use 32 instead of ' ' and 42 instead of '*' :)
Quentin
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
la source
138 bytes
Max Yekhlakov
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
la source
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
la source
(it's my first golf)
freddieknets
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
la source
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
la source
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
la source
Isn't the a function defined in your Python equivalent to + on lists?
Esolanging Fruit
@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
Okay, that makes sense.
Esolanging Fruit
2

Powershell, 88 bytes

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

Groovy 118

10.times{(it*3).upto 3+it*4,{println' '*(39-it)+'/'+'*'*it*2+'\\'}};12.times{println' '*35+'|'+(it>10?'_':'-')*8+'|'}
cfrick
la source
1
Why 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
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
la source
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
la source
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
la source
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
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
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
la source