Christmas quine!

10

0

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)

Manishearth

Posted 2013-12-19T06:11:37.653

Reputation: 709

"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. :/ – Justin – 2013-12-19T06:49:39.530

Answers

16

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

Dom Hastings

Posted 2013-12-19T06:11:37.653

Reputation: 16 415

3Nice trick with the baubles! – Manishearth – 2013-12-19T17:29:51.640

2I love the inclusion of "We wish you a merry Christmas!" – Iszi – 2013-12-19T17:46:37.237

11

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

Doorknob

Posted 2013-12-19T06:11:37.653

Reputation: 68 138

5In my mind you cheated, but you're right about the rules. Outsmarted by a doorknob. Anyway, here's your upvote, for making me smile :) – Manishearth – 2013-12-19T14:52:07.547

1@Manishearth Yep, we bend the rules a lot here! Part of the fun. :P (Ex. 0 character quines, etc) – Doorknob – 2013-12-19T15:45:25.687

@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. – Iszi – 2013-12-19T17:59:10.977

4

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

hildred

Posted 2013-12-19T06:11:37.653

Reputation: 1 329

4

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.

Ilmari Karonen

Posted 2013-12-19T06:11:37.653

Reputation: 19 513