fastler
2014-11-30 10:56:07
Quines:
[INDENT]What are they?[/INDENT]
[INDENT][INDENT]Quines, in short, are curious pieces of code that can write themselves back character for character.
For further reading check out: Wikipedia and this collection The Quine Page[/INDENT][/INDENT]
[INDENT]Why should you care?[/INDENT]
[INDENT][INDENT]Because.[/INDENT][/INDENT]
[INDENT]What does it look like?[/INDENT]
[INDENT][INDENT]Brace yourself. This is the compactest one I could find, at the time of writing, that works in Simba:[/INDENT][/INDENT]
[INDENT][INDENT]
const a='const a=';b='begin writeln(a,#39,a,#39#59#98#61#39,b,#39#59#10,b) end.';
begin writeln(a,#39,a,#39#59#98#61#39,b,#39#59#10,b) end.[/INDENT][/INDENT][INDENT][INDENT]Credit: Geoffrey A Swift (blimey@toke.com)
Note: I changed write() to writeln()[/INDENT][/INDENT]
[INDENT]What is that?[/INDENT]
[INDENT][INDENT]It's a Quine! Let me break it down piece by piece so we can better understand how it works.
Even I at the time of writing this don't know what's exactly going on. Soon enough all shall be made clear.
Right from the start two constants are declared,
a:
const a='const a=';and b:b='begin writeln(a,#39,a,#39#59#98#61#39,b,#39#59#10,b) end.';"a" is the "initial" part of the script and "b" is the "body+end" of the script.
The "body+end" of the script is then actually executed on the next line with:
begin writeln(a,#39,a,#39#59#98#61#39,b,#39#59#10,b) end.This outputs the constants a and b in the appropriate locations andany additional characters needed in between to recreate the script.
And let's not forget the important "end." to "finalize" the code.
For quick reference:
39 is '
59 is ;
98 is b
61 is =
10 is new line feed
[/INDENT][/INDENT]
[INDENT]Now what?[/INDENT]
[INDENT][INDENT]Well, I guess that's it. But nothing is stopping you from attempting to make it even shorter.
Or perhaps write your own! There are an infinite number of ways to make a Quine! Shortness isn't a requirement.
Some people make their Quines ridiculously complex just for the heck of it, sometimes even over several programming languages.
If you have one to share, post it below![/INDENT][/INDENT]