palindromic C programs

Steven Pemberton steven at mcvax.UUCP
Tue Sep 4 01:45:31 AEST 1984

> Are there any programs out there that when program
> 'foo' is executed it creates source for program 'bar' and vice-
> versa?  The result would be a bistable self generating program.
> And if bistable is possible, how about tristable, etc.?

In issue 47 of the Algol Bulletin, Chris Thomson of the Chion Corporation
presented, apart from a self-replicating Algol 68 program, ones that
replicated after 2 cycles (thus a=>b=>a), 3 cycles, 9 cycles, and then
finally a program that replicates itself after a random-length cycle of
expected length 1000!

For those of you interested, here is that last one:

(.INT s:=    0,e:=123;.STRING a="(.INT s:=    0,e:=123;
  .STRING a="";s:=(s*9+7)%*1000000;print(2*(a[:9]+whole(

Subscripts can be used to get a substring of a string, eg a[15:33].  a[33:]
means from 33 to the end. % is integer division, %* is mod, (b|v1|v2) is the
same as C's e?v1:v2 and whole converts a value to a string.

More information about the Comp.lang.c mailing list