JavaScript Quine Contest entries

This is a full lising of all valid quines submitted to the JavaScript Quine Contest that ran on Webgraphics from 2004-08-31 to 2004-09-12. If you want to know more about the contest, I urge you to go to either the original posting, the mid-contest followup, or the contest summary.

Entries by Patrick H. Lauke

Patrick was the first person to submit a valid quine. His quine was large, but it used a whole different approach than that of all the other entries - a function expression wrapper and call, and the built in JavaScript string escaping methods. He's put up a page about his quine entries on his blog.

// 2004-09-01 00:01:53 UTC, 193 characters

(function redux(){q='\'';s='\\';a='return"(function redux(){q="+q+s+q+q+";s="+q+s+s+q+";a="+q+a+q+";"+a+"})()";';return"(function redux(){q="+q+s+q+q+";s="+q+s+s+q+";a="+q+a+q+";"+a+"})()";})()

// Prettyprinted:
(function redux(){
    q='\'';
    s='\\';
    a='return"(function redux(){q="+q+s+q+q+";s="+q+s+s+q+";a="+q+a+q+";"+a+"})()";';
    return"(function redux(){q="+q+s+q+q+";s="+q+s+s+q+";a="+q+a+q+";"+a+"})()";
})()


// 2004-09-01 00:19:26 UTC, 181 characters
// He cut the function name down from redux to r in his final submission.

(function r(){q='\'';s='\\';a='return"(function r(){q="+q+s+q+q+";s="+q+s+s+q+";a="+q+a+q+";"+a+"})()";';return"(function r(){q="+q+s+q+q+";s="+q+s+s+q+";a="+q+a+q+";"+a+"})()";})()

// Prettyprinted:
(function r(){
    q='\'';
    s='\\';
    a='return"(function r(){q="+q+s+q+q+";s="+q+s+s+q+";a="+q+a+q+";"+a+"})()";';
    return"(function r(){q="+q+s+q+q+";s="+q+s+s+q+";a="+q+a+q+";"+a+"})()";
})()

Entries by Mathieu 'P01' HENRI

Mathieu produced a number of nice elegant quines, all using either the unescape or the String.fromCharCode methods for escaping.

// 2004-09-01 12:08:47 UTC, 141 characters

a='a=0;b=a.replace(6-6,String.fromCharCode(39)+a+String.fromCharCode(39))';b=a.replace(6-6,String.fromCharCode(39)+a+String.fromCharCode(39))

// Prettyprinted:
a='a=0;b=a.replace(6-6,String.fromCharCode(39)+a+String.fromCharCode(39))';
b=a.replace(6-6,String.fromCharCode(39)+a+String.fromCharCode(39))


// 2004-09-01 13:45:07 UTC, 61 characters

a='b="a=%27"+a+"%27;"+unescape(a)';b="a='"+a+"';"+unescape(a)

// Prettyprinted:
a='b="a=%27"+a+"%27;"+unescape(a)';
b="a='"+a+"';"+unescape(a)


// 2004-09-02 16:44:12 UTC, 57 characters

a='"a=%27"+a+"%27;"+unescape(a)';"a='"+a+"';"+unescape(a)

// Prettyprinted:
a='"a=%27"+a+"%27;"+unescape(a)';
"a='"+a+"';"+unescape(a)


// 2004-09-02 16:44:12 UTC, 125 characters

a='String.fromCharCode(97,61,39)+a+String.fromCharCode(39,59)+a';String.fromCharCode(97,61,39)+a+String.fromCharCode(39,59)+a

// Prettyprinted:
a='String.fromCharCode(97,61,39)+a+String.fromCharCode(39,59)+a';
String.fromCharCode(97,61,39)+a+String.fromCharCode(39,59)+a

Entries by David Lindquist

David was the most prolific contestant, with many submitted quines using various methodologies. He managed to both create the smallest valid quine (47 characters) in the contest and the most elegant quine (67 characters).

// 2004-09-01 20:58:10 UTC, 144 characters

q='String.fromCharCode(113)+String.fromCharCode(61)+String.fromCharCode(39)+q+String.fromCharCode(39)+String.fromCharCode(59)+"eval(q)"';eval(q)

// Prettyprinted:
q='String.fromCharCode(113)+String.fromCharCode(61)+String.fromCharCode(39)+q+String.fromCharCode(39)+String.fromCharCode(59)+"eval(q)"';
eval(q)


// 2004-09-01 22:11:25 UTC, 61 characters

q='"q="+unescape("%27")+q+unescape("%27")+";eval(q)"';eval(q)


// Prettyprinted:
q='"q="+unescape("%27")+q+unescape("%27")+";eval(q)"';
eval(q)


// 2004-09-01 22:50:43 UTC, 55 characters

q='unescape("q=%27")+q+unescape("%27;eval(q)")';eval(q)

// Prettyprinted:
q='unescape("q=%27")+q+unescape("%27;eval(q)")';
eval(q)


// 2004-09-02 02:33:44 UTC, 51 characters

q='a=unescape("%27");"q="+a+q+a+";eval(q)"';eval(q)

// Prettyprinted:
q='a=unescape("%27");"q="+a+q+a+";eval(q)"';
eval(q)


// 2004-09-02 07:26:17 UTC, 47 characters

eval(q='a=unescape("%27");"eval(q="+a+q+a+")"')

// Prettyprinted:
eval(q='a=unescape("%27");"eval(q="+a+q+a+")"')

// 2004-09-03 03:03:21 UTC, 47 characters
// And a bit more elegant: 

eval(q='"eval(q="+(a=unescape("%27"))+q+a+")"')

// Prettyprinted:
eval(q='"eval(q="+(a=unescape("%27"))+q+a+")"')


// 2004-09-02 17:34:39 UTC, 92 characters
// void('eval'): 

q='q=;a=unescape("%27");q.replace(/=/,"="+a+q+a)';a=unescape("%27");q.replace(/=/,"="+a+q+a)

// Prettyprinted:
q='q=;a=unescape("%27");q.replace(/=/,"="+a+q+a)';
a=unescape("%27");
q.replace(/=/,"="+a+q+a)


// 2004-09-03 14:38:54 UTC, 92 characters
// And a little more elegant: 

q='q=;q.replace(/=/,"="+(a=unescape("%27"))+q+a)';q.replace(/=/,"="+(a=unescape("%27"))+q+a)

// Prettyprinted:
q='q=;q.replace(/=/,"="+(a=unescape("%27"))+q+a)';
q.replace(/=/,"="+(a=unescape("%27"))+q+a)


// 2004-09-03 21:30:24 UTC, 92 characters
// Another elegant varition: 

(q='(q=).replace(/=/,"="+(a=unescape("%27"))+q+a)').replace(/=/,"="+(a=unescape("%27"))+q+a)

// Prettyprinted:
(q='(q=).replace(/=/,""+(a=unescape("%27"))+q+a)').replace(/=/,""+(a=unescape("%27"))+q+a)


// 2004-09-04 00:37:29 UTC, 131 characters

unescape((q="%75%6e%65%73%63%61%70%65%28%28%71%3d%22%q%22%29%29%2e%72%65%70%6c%61%63%65%28%22%25%71%22%2c%71%29")).replace("%q",q)

// Prettyprinted:
unescape((q="%75%6e%65%73%63%61%70%65%28%28%71%3d%22%q%22%29%29%2e%72%65%70%6c%61%63%65%28%22%25%71%22%2c%71%29")).replace("%q",q)


// 2004-09-04 02:58:59 UTC, 67 characters
// Radically improved:

unescape(q="unescape(q=%22*%22).replace(%22*%22,q)").replace("*",q)

// Prettyprinted:

unescape(q="unescape(q=%22*%22).replace(%22*%22,q)").replace("*",q)


// 2004-09-04 03:22:51 UTC, 63 characters

unescape(q="unescape(q=%22*%22).replace('*',q)").replace('*',q)

// Prettyprinted:
unescape(q="unescape(q=%22*%22).replace('*',q)").replace('*',q)


// 2004-09-04 22:05:07 UTC, 157 characters
// void('unescape')

a='\'';b='\\';q='a=AABBAAAA;b=AABBBBAA;q=AAxAA;q.replace(/A{2}/g,a).replace(/B{2}/g,b).replace(/x/,q)';q.replace(/A{2}/g,a).replace(/B{2}/g,b).replace(/x/,q)

// Prettyprinted:
a='\'';
b='\\';
q='a=AABBAAAA;b=AABBBBAA;q=AAxAA;q.replace(/A{2}/g,a).replace(/B{2}/g,b).replace(/x/,q)';
q.replace(/A{2}/g,a).replace(/B{2}/g,b).replace(/x/,q)

Entries by Erik Kastner

Erik was the first person to submit a valid quine in his first entry.

// 2004-09-04 00:01:37 UTC, 143 characters

q=String.fromCharCode(34);a="q=String.fromCharCode(34);a=X;a.replace(String.fromCharCode(88),q+a+q);";a.replace(String.fromCharCode(88),q+a+q);

// Prettyprinted:
q=String.fromCharCode(34);
a="q=String.fromCharCode(34);a=X;a.replace(String.fromCharCode(88),a+q+a);";
a.replace(String.fromCharCode(88),a+q+a);


// 2004-09-04 14:35:42 UTC, 87 characters

q=unescape('%'+22);a="q=unescape('%'+22);a=X;a.replace(/X/,q+a+q)";a.replace(/X/,q+a+q)

// Prettyprinted:
q=unescape('%'+22);
a="q=unescape('%'+22);a.replace(/X/,q+a+q)";
a.replace(/X/,q+a+q)

Entries by Dylan Parker

Dylan had evidently worked on this some before he submitted any of his entries, because he posted a batch of them in his first entry. His are the entries that provides most variation on the theme, and are among other things only ones that work through array handling mechanisms.

// 2004-09-07 04:08:24 UTC, 79 characters

s="q=unescape('%'+'22');'s='+q+s+q+';'+s";q=unescape('%'+'22');'s='+q+s+q+';'+s

// Prettyprinted:
s="q=unescape('%'+'22');'s='+q+s+q+';'+s";
q=unescape('%'+'22');
's='+q+s+q+';'+s


// 2004-09-07 04:08:24 UTC, 160 characters
// Using regex in a different way:

s="s=;q=unescape('%'+'22');s.search(/(..)(.*)/);RegExp.$1+q+RegExp.$_+q+RegExp.$2;";q=unescape('%'+'22');s.search(/(..)(.*)/);RegExp.$1+q+RegExp.$_+q+RegExp.$2;

// Prettyprinted:
s="s=;q=unescape('%'+'22');s.search(/(..)(.*)/);RegExp.$1+q+RegExp.$_+q+RegExp.$2;";
q=unescape('%'+'22');
s.search(/(..)(.*)/);
RegExp.$1+q+RegExp.$_+q+RegExp.$2;


// 2004-09-07 04:08:24 UTC, 196 characters
// Obfuscated:

a=["('');","join","().","reverse","];'+a.","+q+'","(q+','+q)","join","q+a.","a=['+",";s='","('%'+'22')","unescape","q="];q=unescape('%'+'22');s='a=['+q+a.join(q+','+q)+q+'];'+a.reverse().join('');

// Not as well as the others because of it's structure, but in any case...
// Prettyprinted:
a=[
    "('')",
    "join",
    "().",
    "reverse",
    "];'+a.",
    "+q+",
    "(q','+q)",
    "join",
    "q+a.",
    "a=['+",
    ";s='",
    "('%'+'22')",
    "unescape",
    "q="];
q=unescape('%'+'22');
s='a=['+q+a.join(q+','+q)+q+'];'+a.reverse().join('');

// 2004-09-07 04:08:24 UTC, 137 characters
// Near-palindrome:

s=")''(nioj.)(esrever.)''(tilps.s+';'+q+s+q+'=s';)'22'+'%'(epacsenu=q";q=unescape('%'+'22');'s='+q+s+q+';'+s.split('').reverse().join('')

// Prettyprinted:
s=")''(noij.)(esrever.)''(tilps.s+';'+q+s+q+'=s';)'22'+'%'(epacsenu=q";
q=unescape('%','22');
's='+q+s+s+';'+s.split('').reverse().join('')

// 2004-09-07 06:50:51 UTC, 52 characters

s="q=unescape('%'+22);'s='+q+s+q+';eval(s)'";eval(s)

// Prettyprinted:
s="q=unescape('%'+22);'s='+q+s+q+';eval(s)'";
eval(s)


// 2004-09-08 06:46:25 UTC, 43 characters
// This one is not valid, but it's worthy of a mention since it's the smallest one:

eval(s=%22q='%'+22;'eval(s='+q+s+q+')'%22)

// Prettyprinted:
eval(s=%22q='%'+22;'eval(s='+q+s+q+')'%22)