Post Archive

› August 31, 2004

JavaScript Quine Contest

  • Reported by liorean

So, you know what a quine is? No? It's a script that outputs it's own source code listing. This is a contest to write a JavaScript quine. The contest will run until 2004-09-12. Winners in the cathegories First Posted Quine, Fastest Quine, Smallest Quine, and Most Elegant Quine will be given a GMail invite (unless they already have one, in which case they will have to do with the glory of having won the contest). Content rules will be as follows:

Updated to clarify things a bit.

  • Since JavaScript doesn't have a standard output, the return value of the last statement in the quine, which must be a string, will be considered the output.

  • The usage of the internal deparser at the top level of the quine is not allowed. This means for example using a wrapper function and explicitly or implicitly calling the toString or toSource methods on this function from within.

    (Meaning that I don't want to see something like this:)

    (function quine(){return '('+quine+')();';})();

    Of course, any usage of wrapper functions where you do not use the internal deparser is allowed.

  • The quine must be self contained, meaning that no code other than that contained in the quine itself is allowed. (Specifically, a quine that uses a function wrapper must by necessecity also contain a call on said function wrapper.)

  • The quine must run in the newest version of at least two out of the four browsers IEW, Mozilla FireFox, Opera, Safari.
  • Submissions should be mailed to me, liorean at gmail dot com.

How may I test if the quine works? Well, the easiest way is to use a javascript: pseudo-uri like this:

javascript:<quine>
where the result should be:
<quine>

Comments

1. August 31, 2004 10:54 AM

Quote this comment

Mathieu 'P01' HENRI Posted…

Is it possible to output the result in an alert( ) or do you absolutely want it to be returned ?

2. August 31, 2004 02:59 PM

Quote this comment

liorean Posted…

I wanted the code to be host independent, really, but I think I can take alerting it using a single alert. However, I don't see why you would want to do that, since you then have to add the alert code to the generated source as well. Remember that the return value without the alert would be just the argument you send to the alert, minus the code calling the alert.

3. August 31, 2004 03:46 PM

Quote this comment

liorean Posted…

Just a clarification: By return value, I don't mean the return statement in a function. All expressions (as differentiated from statements) have a return value. For example, the return value of the expression 1+2 is 3.

4. August 31, 2004 05:03 PM

Quote this comment

patrick h. lauke Posted…

just emailed my entry. nice one, quite challenging little conundrum.

5. August 31, 2004 05:49 PM

Quote this comment

liorean Posted…

Another clarification: A quine must be self contained. The quine must by itself generate the entire source listing of itself. If you send just the quine and nothing but the quine to the scripting engine, the quine must execute and return a string containing it's entire source listing, such as it was sent to the scripting engine in the first place.

6. August 31, 2004 06:01 PM

Quote this comment

Matthijs Aandewiel Posted…

Wow, i might go a little off-topic here, but you actually got me started messing around with Javascript. This is great fun!

7. August 31, 2004 08:12 PM

Quote this comment

patrick h. lauke Posted…

hmmm...apparently even more challenging than i thought. the actual contest rules are a tad vague, though. hopefully liorean will update them to save other poor souls the frustration...

8. August 31, 2004 08:31 PM

Quote this comment

liorean Posted…

Update done. I hope that makes it a bit clearer.

9. September 1, 2004 10:53 AM

Quote this comment

David Lindquist Posted…

A little late to the game, but just submitted mine. Fun little challenge!

10. September 1, 2004 07:07 PM

Quote this comment

liorean Posted…

A small status report

Patrick was the first to post a working, valid quine at 193 characters (later somewhat reduced in size), thus giving him the First Posted Quine win. After him, Matthieu and David have both submitted valid quines.

11. September 1, 2004 11:32 PM

Quote this comment

Jimmy Cerra Posted…

I guess the program, "1" won't be considered. After all, "javascript:1" returns "1"

12. September 2, 2004 03:38 AM

Quote this comment

Mathieu 'P01' HENRI Posted…

Jimmy: I thought about it too ^__^ but the first rule is clear on that point. The last statement in the quine, which must be a string, will be considered the output.

13. September 2, 2004 06:53 AM

Quote this comment

liorean Posted…

Yeah. This was just the reason for including that limit in the rules. I guess it technically could be considered to be a quine, but I'll not be giving away any GMail invites for it.

14. September 4, 2004 07:38 AM

Quote this comment

Edwin Martin Posted…

I tried to be smart and came up with this quine:

null

javascript:null does return "null".

Still, it is not a valid quine. It conflicts with rule 1. The quine returns the null value, not the string "null". It is only converted to the string "null" at the moment you print the quine.

So for everyone who also came up with something like this: it's not valid.

15. September 4, 2004 07:54 AM

Quote this comment

Edwin Martin Posted…

Update: so how do you know for sure it returns a string? Instead of typing javascript: <quine>, type:

javascript: typeof <quine>

The result must be the word string, or it is not a valid quine.

16. September 6, 2004 11:33 PM

Quote this comment

Dylan Posted…

Curse you and your time-eating contest! Ahh... where have the hours gone?!?

17. September 7, 2004 10:00 AM

Quote this comment

Phantom Posted…

Just posted mine.It was a real chalenge.

18. September 12, 2004 09:58 PM

Quote this comment

patrick h. lauke Posted…

for those interested, now that the contest is over i've posted my javascript quine (which got the "first posted quine" prize) over on my site.

19. April 25, 2005 04:32 PM

Quote this comment

Nathan Bird Posted…

( function (x) { return "(" + x + ")(" + x + ")"; } )( function (x) { return "(" + x + ")(" + x + ")"; } ) I think I'm a bit late for the contest, but didn't see anyone else mentioning this.

20. July 12, 2005 06:54 AM

Quote this comment

Jesper Christensen Posted…

Wouldn't <script></script> be the obvious winner here or does the rules not allow that?

21. July 12, 2005 02:56 PM

Quote this comment

Mathieu 'P01' HENRI Posted…

This is one arguable since we can consider the code is an empty string, but I think it breaks the first rule like: null.

22. July 12, 2005 02:57 PM

Quote this comment

Mathieu 'P01' HENRI Posted…

This is one arguable since we can consider the code is an empty string but I think it breaks the first rule like null.