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\$
1
  • \$\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
    Commented Dec 19, 2013 at 6:49

4 Answers 4

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\$
2
  • 3
    \$\begingroup\$ Nice trick with the baubles! \$\endgroup\$ Commented Dec 19, 2013 at 17:29
  • 2
    \$\begingroup\$ I love the inclusion of "We wish you a merry Christmas!" \$\endgroup\$
    – Iszi
    Commented Dec 19, 2013 at 17:46
9
\$\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\$
4
  • 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\$ Commented Dec 19, 2013 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
    Commented Dec 19, 2013 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
    Commented Dec 19, 2013 at 17:59
  • 1
    \$\begingroup\$ "You never said we couldn't use network access" No, but loopholes that are forbidden by default did. \$\endgroup\$
    – Makonede
    Commented May 27, 2021 at 21:07
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 and acknowledge you have read our privacy policy.

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