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)
  • \$\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, 2013 at 6:49

4 Answers 4



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

        (function _()
     {return('        (')
           ;'We w'
         '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'

The zeroes are baubles and look best in the editor:

Hooray for syntax highlighting!

Output in Chrome Developer tools

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


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

s.gsub! /\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
  • 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\$ 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
    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
    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
    May 27, 2021 at 21:07


$_=<<'the source';eval $_;

     "/perl \n".
   " source';eva".
  "l \$_;\n${_}th".
 "e source\n";# Mery 
#Christmas to all !!!

the source

Here's a tiny one in GolfScript:


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:

    " "

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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