Quine Time

Status
Not open for further replies.
Today we're going to cover the topic of quines.

What is a Quine?
A quine is a computer program that does one thing. With no input it produces a copy of its own source code as its only output. Quines are a form of self replicating programs.

That seems pointless.
It largely is. A quine is really more of a thought exercise. You can do some fun things. You can write quines that can run the compiler and then execute the output (or just run the output if it's a language like Python. Fun fact, Windows XP can run about 3000 processes before it hits it's limit.

Not technically quines, you can write programs that output the source in another language. C->Java for example. You could even chain languages like that C->Java->Python->C...

An example in C
Code:
#include <stdio.h>
int main() {
    char *s = "#include <stdio.h>%cint main() {%c%cchar *s = %c%s%c;%c%cprintf(&s,10,10,9,34,&s,34,10,9,10,9,10);%c%creturn 0;%c}";
    printf(&s,10,10,9,34,&s,34,10,9,10,9,10);
    return 0;
}
What's with all the numbers in the printf()?
They're ASCII character codes. Equivalent to \n, \t, and ". They help make the output formated the same as the original source without them I would need to put the escape characters into the string, which would format the string pointer value in the output. The ASCII codes keep everything identical from the original source to the quine's output.
 
Status
Not open for further replies.
Top