Autoexotic programming

hoey at nrl-aic.ARPA hoey at nrl-aic.ARPA
Sat Sep 1 03:10:00 AEST 1984


From:  Dan Hoey <hoey at nrl-aic.ARPA>

The purpose of a self-reproducing program is to be a backup, in case
the source is lost.  Thus it is unwise to rely on the presence of the
source file, as in some proposed solutions.

The only short examples provided so far assume that the character code
for double-quote is 34.  Here's an 89-character modification that
doesn't depend on the character set (remove the line break).

main(){char*a="main(){char*a=%c%s%c,q='%c';printf(a,q,a,q,q);}",q='"';
printf(a,q,a,q,q);}

Of course, we may as well be tasteful and print a trailing newline, but
that takes 131 characters, as below (remove the internal line breaks).

main(){char*a="main(){char*a=%c%s%c,q='%c',b='%c%c';
printf(a,q,a,q,q,b,b,b,'%cn');}%c",q='"',b='\\';
printf(a,q,a,q,q,b,b,b,'\n');}

The only palindrome previously seen has an unclosed comment.  This can
be repaired until c cares about nested comments.

/**/main(){}/*/}{)(niam/**/

You may wish to put a newline on the beginning and end of that program.

Dan
1U23R11R'''1U23R11R'''



More information about the Comp.lang.c mailing list