The Classic C Quine (2003)
susam.net
susam.net
I pondered a bit on this and thought it's impossible, but still, I made this repo as a challenge:
https://github.com/ggerganov/diff-challenge
Amazingly, someone managed recently to propose a solution for the first step [0]. Not sure if a next step is possible though..
[0] https://github.com/ggerganov/diff-challenge/commit/e4d210c16...
1,Nc1,3
< HERE IT REPRODUCES
< ITS OWN N-LINE IMAGE
< ...
---
> #!/bin/sh
> head -n2 $0 | diff - /dev/null
> exit 0
Since "quining" via $0 is evidently fair game, that simplifies things a lot. Here you go: #!/bin/sh
sed -e 's/^X//' <<!
X1,9c1,3
$(sed -e s'/^/< /' $0)
X---
X> #!/bin/sh
X> head -n2 \$0 | diff - /dev/null
X> exit 0
!
On first try, I didn't escape the dollar sigil on $0, so that got expanded to ./x3.sh, resulting in a minor difference. But since we are not doing any true quining, all I had to do was add the backslash without having to rack my brain on how to compensate for that character elsewhere; the "reproduce self accurately" requirement is trivially taken care of with $0.With the above template, you can diff back to any body of text, so it can be easily continued.
Having $0 available does seem to help a lot to solve the challenge.
Y = (X + information) + X diff Y (This is kind of golden ratio-ish, imo)
It seems to be self referential which doesn't make it impossible, just maybe impossible.
I think the trick here would be calculating the lower bound of a massive block of text that could be encoded somehow to produce a sort of hash collision.
The program would essentially just read from a big chunk of text, and reconstruct the actual source code.
You'd have a separate program to read the previous text, read your program, and find a collision in your encoding scheme that satisfied your changes and also diffed correctly.
What that encoding algorithm is, I don't know, and I'm not sure it can exist. But if it does, I think you'd have to have to have a pretty big chunk of data to collide to even write a hello world program.
This is a pretty interesting problem, but I bet it can be reduced to a simpler computability/information theory deal. I'll be thinking about this all day.
#include<stdio.h>
int main(){
char q='"',n='\n',b='\\';
char*f="#include<stdio.h>%cint main(){%c char q='%c',n='%cn',b='%c%c';%c char*f=%c%s%c;%c printf(f,n,n,q,b,b,b,n,q,f,q,n,n,n);%c}%c";
printf(f,n,n,q,b,b,b,n,q,f,q,n,n,n);
}It is written and interpreted using the cat language, which is an interpreted language in which every possible byte stands for a self-printing action, and those actions are carried out in order for all bytes of the input.
It is also written in the hash-bang language, which is placed into a file to specify to the OS kernel what interpreter to use for the file.
So first this is interpreted as a hash-bang language statement, which then causes the cat interpreter to be applied, causing it to be a cat language statement.
The hash-bang interpretation is what induces the binding between the cat interpreter and the hash-bang statement, evoking the cat language interpretation.
:)
#!/bin/sed 1d
Hello, World!
But if the complexity of sed 1d is replaced by the pure cat implementation of the Text language which omits nothing, then self-reproducing behavior is obtained in stand-alone delivery form. touch foo && chmod +x foo
./foo
Unless one considers the commands to create & invoke it (as above) to be a part of the "source code" of course...For esoteric programming languages this might be more complete: https://esolangs.org/wiki/List_of_quines
yields falsehood when preceded by its quotation
Some people seem to like Quine's prose; I found it deliberately obscure and over-elaborate.