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!
code-golf
ascii-art
kolmogorov-complexity
caird coinheringaahing
la source
la source
Réponses:
Golfscript,
8477767572 charactersDifferent approach from Howard's. Click on the character count to try it.
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):la source
'\\'n
pull the newline into the string (+/- 0 characters) and now the backslash no longer needs to be escaped (-1 character).4*4+
is the same as)4*
and'_-'[=]
can be written'_-'1/=
which makes the last+
obsolete.Haml & Sass
37 + 277 = 314
Haml:
Sass:
*Sass allows control directives, concatenation, and variable dereference. All of which are useful when styling, but verbose while golfing.
gets generated into:
HTML:
CSS:
the resulting page
la source
CJam, 62 bytes
Try it online!
How it works
la source
GolfScript, 79 characters
Try the code here. Note that the line breaks aren't optional in this code
la source
Python,
148129126121 charactersThanks to Falko for saving 3 characters and to flornquake for brilliantly saving another 5!
la source
'**'*j
to save 3 characters. Apart from this my solution converges to the exact same code. :)for c in'-'*11+'_':print' '*35+'|'+c*8+'|'
.Bash,
236 19719310 bytes of code + 1-byte filename + 182-byte data file = 193 bytes total
Explanation
y
is a file containing the Yggdrasil, without a trailing new line, compressed with the zopfli algorithm (invoked aszopfli --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
. Ifj
exists, it will be overwritten.The base64 of
y
is (usebase64 -d
to obtain the original file):And the md5sum is:
la source
C, 169
Ungolfed (and slightly disentangled):
la source
Ruby - 100
Puts auto-flattens, so we can collect all the lines even in nested arrays. Needs Ruby 1.9
Try at ideone
la source
PowerShell
104101la source
C#
258234bytesThanks to some annoymous user for the suggested edits making good use of the String.PadLeft method!
The code is pretty simple, not much left to golf.
Formatted code:
la source
\r
is pointless here. This is code golf.J,
98 88 8475la source
Perl, 127
Ungolfed:
la source
Ruby -
139129126123121Hoisted "puts" outside of array creation (suggestion from bitpwner).
Ungolfed ("puts" unhoisted):
la source
PHP
223202181160156Edit 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 verboseEdit 2: Thanks everyone for the suggestions!
Golfed:
Readable:
Output: http://brobin.me/yggdrasil.php
la source
(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++)
withfor($i=12;$i-->0;)
and$i==11
with$i==0
.$s(($i==0?'_':'-'),8)
with$s($i?'-':'_',8)
. (==> -5 chars)$s('*',$j*2)
with$s('**',$j)
. I think that's the last improvement that I can find.($j*2)
in inner for to($j++*2)
and removing$j++
fromfor()
argumentsfor($i=12;$i-->0;)
can be shortened tofor($i=12;$i--;)
- another 2 chars.Delphi 429
Will try to improve later.
Golfed
ungolfed
la source
Javascript,
288281Chrome hides duplicated
console.log
s, use IE instead.Ungolfed:
la source
for(i=0;i++<39-w;)
instead offor(i=0;i<39-w;++i)
, and so on. Also,p=console.log
instead ofc=console
andp
instead ofc.log
(although I only tested the latter in Node.js, it doesn't work in Firefox). This saves 12 bytes.c=console.log
didn't work in Chrome either, so I didn't use it. The for loop tricks save 7 bytes though.JavaScript (console.log),
168166(Whitespace for readability only)
la source
C (219)
Thanks to everyone for the golfing tips -- managed to get it down to 219. Don't think it'll go much lower.
Required includes:
la source
32
instead of' '
and42
instead of'*'
:)Haskell,
153148Straight-forward, no tricks, just plain golfing:
The
%
operator draws a single line, its first argument being aString
of length 3 containing the borders and the fill characters in that line (now assuming exactly 3Char
s, saving 5 bytes), the second, anInt
, 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" betweenChar
andString
. In this second version, I also made#
infinite and introduced atake 85
to make it finite again (no bytes saved, unfortunately).The
#
operator creates the sequence for then
argument to%
required for the tree:[0..3], [3..7], ...
concatenated.&
is just an infix shorthand forreplicate
, which occurs three times.The tree is put together in the last line, the newlines are added by
unlines
.la source
Lua - 164
la source
Mathematica
191178For sure not the best solution:
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.
la source
Java - 286
My first golf.
Golfed:
Ungolfed:
Test here
la source
Python 2, 117
Other versions I tried include:
la source
Pyth,
101100999081 bytesTry it online!
Python 3 translation:la source
a
function defined in your Python equivalent to+
on lists?<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.Powershell, 88 bytes
la source
Groovy 118
la source
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 inprintf
.la source
Racket
223 220 211 204198Golfed:
Ungolfed:
la source
Assembly (MIPS, SPIM),
768671659655654 bytesTry 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.
la source
addi $sp -4
which is reallyaddi $sp $sp -4
is from SPIM or MIPS in general, so if anyone else does, please let me know.Cobra - 166
228260la source