10
\$\begingroup\$

In the language of your choice, write a program that is arranged in the shape of a Christmas tree that prints itself in the same shape.

What is not allowed:

  • Printing out the source file
  • Code that is nothing but statements that get echoed by an interpreter by virtue of them being literals (eg just using a tree-shaped tower of lists in python)
\$\endgroup\$
  • \$\begingroup\$ "Printing out the source file" is not allowed, but is reading source code (not from file) and printing it allowed? If it is not, then this is practically impossible with Befunge. :/ \$\endgroup\$ – Justin Dec 19 '13 at 6:49
16
\$\begingroup\$

JavaScript

The 'star' might be a bit too large for the tree...

        (function _()
     {return('        (')
      +(''+''+''+''+'')
             +_+
            ')()'
           ;'We w'
          +'wis'+0+
         'h you a '
        +0+'merry Ch'
       +'ristmas, '+0+
      +'we '+0+'wish y'
     +0+'ou a merry Chr'
    +'istmas, we w'+0+'i'
   +0+'sh you '+0+'a merr'
  +'y Christmas and a h'+0+
 +'appy'+0+'new year! Ho ho'
+0+' ho! Merry '+0+'Christma'
            +'s!'
            })()

The zeroes are baubles and look best in the editor:

Hooray for syntax highlighting!

Output in Chrome Developer tools

\$\endgroup\$
  • 3
    \$\begingroup\$ Nice trick with the baubles! \$\endgroup\$ – Manishearth Dec 19 '13 at 17:29
  • 2
    \$\begingroup\$ I love the inclusion of "We wish you a merry Christmas!" \$\endgroup\$ – Iszi Dec 19 '13 at 17:46
11
\$\begingroup\$

Ruby

You never said we couldn't use network access... :D

        #
       s="
      open(
     'http:/
    /pastebin
   .com/raw.ph
  p?i=mGzbahp5'
 ).read";s=eval(
s.gsub! /\s/,'');
      puts(
      s+'')

Outputs itself verbatim.

Yes, I could have used a URL shortener, but that would have made it less obvious and amusing :P Also I needed something to take up space; otherwise the tree would be tiny.

Execute like this:

ruby -ropen-uri christmasquine.rb
\$\endgroup\$
  • 5
    \$\begingroup\$ In my mind you cheated, but you're right about the rules. Outsmarted by a doorknob. Anyway, here's your upvote, for making me smile :) \$\endgroup\$ – Manishearth Dec 19 '13 at 14:52
  • 1
    \$\begingroup\$ @Manishearth Yep, we bend the rules a lot here! Part of the fun. :P (Ex. 0 character quines, etc) \$\endgroup\$ – Doorknob Dec 19 '13 at 15:45
  • \$\begingroup\$ @Manishearth Yeah, what Doorknob said. If you don't want a rule bent, you need to include a rule against bending that rule. Hence why the latest "reverse quine" and "mirror quine" challenges had rules against palindromes and quines shorter than 2 characters. \$\endgroup\$ – Iszi Dec 19 '13 at 17:59
4
\$\begingroup\$

perl

#!/usr/bin/perl
$_=<<'the source';eval $_;

          #
         #*#
        print
       "#!/u".
      "sr/bin".
     "/perl \n".
    "\$_=<<'the".
   " source';eva".
  "l \$_;\n${_}th".
 "e source\n";# Mery 
#Christmas to all !!!
         ###
         ###
         #*#

the source
\$\endgroup\$
4
\$\begingroup\$

Here's a tiny one in GolfScript:

   {
  ".~  
 "2/~\
+@@2$*}.
   ~

Note that the code above includes two space characters at the end of the second line from the top; those spaces are essential for correct operation. Also, the code should be saved using Unix-style (LF) linefeeds, not Windows-style CR+LF.


Here's a slightly bigger (and less whitespace-sensitive) one, including a festive message:

     {
    " "
   MERRY
  5*n\+\n
 CHRISTMAS
".~"+2$*1>}
     .
     ~

A mildly interesting feature is that the words MERRY and CHRISTMAS are not string literals, although they are no-ops, and are copied to the output along with the code block surrounding them.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.