[comp.lang.c] Palindromic and portable automatic program

hoey@nrl-aic.arpa (Dan Hoey) (01/02/87)

In message <761@tjalk.cs.vu.nl>, Robbert van Renesse sends us what he
calls a ``PORtable Self-Reproducing Obfuscated Palindrome.''  In an
effort to make his anagram palindromic, he commits an unfortunate
misnomer.  The program he sent is not portable, because it relies on
the ASCII encodings for double-quote, newline, and (!) comma.

Here is a 356-character self-reproducing palindrome without character
set dependencies.  The program contains no newlines, although I have
inserted a few here to avoid mailer difficulties:
================================================================
/**/main(){char*a=/*/};)q,q,a,q,q,811+a(ftnirp;'"'=q,/**/"
/**/main(){char*a=/*/};)q,q,a,q,q,811+a(ftnirp;'c%'=q,/**/c%
s%c%/**/,q='c%';printf(a+118,q,q,a,q,q);}/*/=a*rahc{)(niam/*
*/main(){char*a=/*/};)q,q,a,q,q,811+a(ftnirp;'%c'=q,/**/%c%s
%c/**/,q='%c';printf(a+118,q,q,a,q,q);}/*/=a*rahc{)(niam/**/
"/**/,q='"';printf(a+118,q,q,a,q,q);}/*/=a*rahc{)(niam/**/
================================================================
Some compilers may have problems with programs that do not end with
newline.  To avoid this difficulty, you may prefer the following
561-character self-reproducing palindrome.  This program is two lines
long, consisting of an empty line and a 559-character line; again I
have folded the long line.
================================================================

/**/main(){char*a=/*/};)n,s,s,s,q,q,a,q,q,s,s,s,n,191+a(ftnirp
;'n\'=n,'\\'=s,'"'=q,/**/"c%/**/main(){char*a=/*/};)n,s,s,s,q,
q,a,q,q,s,s,s,n,191+a(ftnirp;'nc%'=n,'c%c%'=s,'c%'=q,/**/c%s%c
%/**/,q='c%',s='c%c%',n='c%n';printf(a+191,n,s,s,s,q,q,a,q,q,s
,s,s,n);}/*/=a*rahc{)(niam/**/c%c/**/main(){char*a=/*/};)n,s,s,
s,q,q,a,q,q,s,s,s,n,191+a(ftnirp;'n%c'=n,'%c%c'=s,'%c'=q,/**/%
c%s%c/**/,q='%c',s='%c%c',n='%cn';printf(a+191,n,s,s,s,q,q,a,q
,q,s,s,s,n);}/*/=a*rahc{)(niam/**/%c"/**/,q='"',s='\\',n='\n';
printf(a+191,n,s,s,s,q,q,a,q,q,s,s,s,n);}/*/=a*rahc{)(niam/**/
================================================================
I would appreciate hearing of any improvements to these programs.

Dan Hoey
1U23R11R'''1U23R11R'''