-
-
Save cowboy/6966747ad374fb97b0ab to your computer and use it in GitHub Desktop.
// Today, I noticed that someone favorited this tweet of mine from 2012: | |
// https://twitter.com/cowboy/status/232587756486938624 | |
// !function $(){console.log('!'+$+'()')}() #quine | |
// So I fooled around for a little bit: | |
// Shortest JavaScript quine? | |
(function _(){return'('+_+')()'})() | |
// Have fun with this one! | |
(function $($_$,_,_$,_$_,$_){return[_=_[$_$](_$[$_++])][_[$_++]][_[$_++]]([][_[$_--]][_[$_++]](_$_,function($$){return _$[$$]||[$_,_$_,_,$_$,$][$_--]},$_++),_[++$_])})('split',',join,call,map',',()\'\\','1821383038303012434430383082',0) |
// Test a quine like so: | |
a= your_quine_code | |
a===eval(a) // must be true | |
// Eg. | |
a= (function _(){return'('+_+')()'})() | |
a===eval(a) // true |
Here`s mine:
can you explain that in greater detail?
I love the example but i am just curious how you got this.
well, if you run it it prints out its own sourcecode. valid in every language.
a cheap trick within the quine rules.
First of all, mine is:
(_=$=>`(_=${_})()`)()
But I prefer:
Uncaught SyntaxError: Unexpected identifier
Uncaught SyntaxError: Unexpected identifier
excellent
Actually, these quines aren't real quines because they read themselves. Here's my take:
const charCode = 34;
const code = [
"const charCode = 34;",
"const code = [",
"",
"];",
"for (let i = 0; i < 2; i++) console.log(code[i])",
"for (let i = 0; i < code.length; i++) console.log(code[2] + ' ' + String.fromCharCode(charCode) + code[i] + String.fromCharCode(charCode) + ',');",
"for (let i = 3; i < code.length; i++) console.log(code[i])"
];
for (let i = 0; i < 2; i++) console.log(code[i]);
for (let i = 0; i < code.length; i++) console.log(code[2] + ' ' + String.fromCharCode(charCode) + code[i] + String.fromCharCode(charCode) + ',');
for (let i = 3; i < code.length; i++) console.log(code[i])
Of course it could be a lot shorter but I just wanted to show that we could add any amount of code and the quine would work with a few tweaks
I made one that creates a string with code to log itself plus the parts around it then evaluates it
a="console.log('a='+String.fromCharCode(34)+a+String.fromCharCode(34)+';eval(a)')";eval(a)
Does this count?
(() => { !function () { console.log(
(${arguments.callee.caller.toString()})()) }() })()
I'VE DONE IT!
I created THE SMALLEST quine, it passes the quine test above and technically is one depending on how you define it.
It also should work in most programming languages!
You're never going to believe how amazing the code is:
0
Yep, that's it. Just the number 0. When run it prints 0, which is the code. It passes the test: 0===eval(0)
making it the smallest quine (although not a very interesting one)
@rubyswolf
It's not a Quine, someone already proposed this idea in this thread, and even if it does, the empty program results with an empty output so `` is the smallest Quine.
oh I missed that one oops @donno2048
without equality sign and function keyword
({0(){alert(`({${this[0]}})[0]()`)}})[0]()
// Never ending eval...
let x ="let x =%22quinner%22;let y=decodeURI(x).replace(/quinner/, x);alert(y);eval(y);";let y=decodeURI(x).replace(/quinner/, x);alert(y);eval(y);
// Never ending eval...
let x ="let x =%22quinner%22;let y=decodeURI(x).replace(/quinner/, x);alert(y);eval(y);";let y=decodeURI(x).replace(/quinner/, x);alert(y);eval(y);
You can test any quine by assigning it to the variable a and then fnaf game checking if a === eval(a) returns true. If it does, the code is a valid quine.
AI sure is making spam more insidious
It may not be the smallest quine, but it is certainly mine.
var joe = [
'dmFyIGpvZSA9IFs=',
'XTs=',
'Y29uc29sZS5sb2coYXRvYihqb2VbMF0pKTs=',
'Zm9yKHZhciBpID0gMDtpPGpvZS5sZW5ndGg7aSsrKXs=',
"Y29uc29sZS5sb2coYCcke2pvZVtpXX0nLGApOw==",
'fQ==',
'Y29uc29sZS5sb2coYXRvYihqb2VbMV0pKTs=',
'Zm9yKHZhciBpID0gMjtpPGpvZS5sZW5ndGg7aSsrKXs=',
'Y29uc29sZS5sb2coYXRvYihqb2VbaV0pKTs=',
'fQ==',
];
console.log(atob(joe[0]));
for(var i = 0;i<joe.length;i++){
console.log(`'${joe[i]}',`);
}
console.log(atob(joe[1]));
for(var i = 2;i<joe.length;i++){
console.log(atob(joe[i]));
}
also a real quine over here:
s=`l=console.log
q=String.fromCharCode(96)
l('s='+q+s+q)
l(s)`
l=console.log
q=String.fromCharCode(96)
l('s='+q+s+q)
l(s)
Here`s mine: