Small introspective program
Jay Skeer
jay at hermix.UUCP
Sat Mar 16 07:22:34 AEST 1991
This one is self-recognizing. I am sure someone can do it shorter.
(Btw, what about lisp's shortest self-repro programs "T", "0", "1", "2", ...)
j'
-------------------
#include <stdio.h>
#define N 18
#define F 8
#define L 80
#define Y Z[k++]
#define P sprintf
char*I="\"%s\",",*B="%s",
M[N*3][L],Z[L],D[N][L]={
"#include <stdio.h>",
"#define N 18",
"#define F 8",
"#define L 80",
"#define Y Z[k++]",
"#define P sprintf",
"char*I=\"\\\"%s\\\",\",*B=\"%s\",",
"M[N*3][L],Z[L],D[N][L]={",
"\"\"},v='\\\\',q='\\\"';",
"main(){int c,i=0,j=0,k,l;",
"for(;i<F;P(M[j++],B,D[i++]));",
"for(i=0;i<N-1;i++,P(M[j++],I,Z))",
"for(k=0,l=0;Z[k]=0,c=D[i][l++];Y=c)",
"((c^v)*(c^q))||(Y=v);",
"for(i=F;i<N;P(M[j++],B,D[i++]));",
"for(i=0;gets(Z);)strcmp(M[i++],Z)&&exit(puts(\"no\"),1);",
"exit(puts(\"yes\"),0);}",
""},v='\\',q='\"';
main(){int c,i=0,j=0,k,l;
for(;i<F;P(M[j++],B,D[i++]));
for(i=0;i<N-1;i++,P(M[j++],I,Z))
for(k=0,l=0;Z[k]=0,c=D[i][l++];Y=c)
((c^v)*(c^q))||(Y=v);
for(i=F;i<N;P(M[j++],B,D[i++]));
for(i=0;gets(Z);)strcmp(M[i++],Z)&&exit(puts("no"),1);
exit(puts("yes"),0);}
More information about the Alt.sources
mailing list