Skip to content

Instantly share code, notes, and snippets.

@sugyan
Forked from 140bytes/LICENSE.txt
Created May 20, 2011 08:58
Show Gist options
  • Select an option

  • Save sugyan/982590 to your computer and use it in GitHub Desktop.

Select an option

Save sugyan/982590 to your computer and use it in GitHub Desktop.
self-reproducing program
function(){
/* Rules: // make sure
(1) anonymous function // to annotate
(2) optionally self-executing // your code
(3) <140 bytes // so everyone
(4) no global vars // can learn
(5) MIT license // from it!
(6) good luck!
*/}
function(){/*Rules: (1) anonymous function (2) optionally self-executing (3) <140 bytes (4) no global vars (5) MIT license (6) good luck!*/}
{
"name": "sample",
"keywords": [ "sample", "original" ]
}
@maettig
Copy link

maettig commented Nov 11, 2011

Some people say it's not a true [Quine](http://en.wikipedia.org/wiki/Quine_(computing\)) if you use eval. I tried to create one without. It's 143 bytes and returns it's own source as a string. Any idea how to save 3 bytes?

function(a,b){return(a='function(a,b){return(a=Q).replace(/Q/,(b=String.fromCharCode(39))+a+b)}').replace(/Q/,(b=String.fromCharCode(39))+a+b)}

@sugyan
Copy link
Author

sugyan commented Nov 11, 2011

It's nice!
how about using unescape instead of String.fromCharCode.

function(a,b){return(a='function(a,b){return(a=Q).replace(/Q/,(b=unescape("%27"))+a+b)}').replace(/Q/,(b=unescape("%27"))+a+b)}

@maettig
Copy link

maettig commented Nov 11, 2011

Perfect! Replacing String.fromCharCode(39) with unescape("%27") looks a little strange but is a very cool idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment