[net.lang.c] palindromic C programs

eklhad@ihnet.UUCP (K. A. Dahlke) (08/24/84)

~~~~~~~~

Many articles have addressed the self-reproducing C program.
Are there any C programs which print themselves in reverse?
I believe it can be done, but it will take me a while.

Are there any C programs which run, and are palindromes themselves?
I can think of one:
main(){}/*/}{)(niam
This is probably the only way to do it,
since key-words become variables when reversed.
-- 

Karl Dahlke    ihnp4!ihnet!eklhad

johng@metheus.UUCP (John Gregor) (08/27/84)

There have been quite a few examples of C programs that repeat
themselves.  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.?

	{the world}!tektronix!ogcvax!metheus!johng
	    John Gregor to non-machines.

"This is a test of the Emergency Broadcast System.  If this had been
an actual emergency, do you really think we'd stick around to tell you?"

paulsc@tekecs.UUCP (Paul Scherf) (08/28/84)

I once wrote a FORTRAN program that printed a C program that
printed a Pascal program that printed the original FORTRAN
program. Does that count?

Paul Scherf, Tektronix, Wilsonville, Oregon, USA
paulsc@tekecs.UUCP

adamm@BBNCCS.ARPA (08/29/84)

From:  Adam Moskowitz <adamm@BBNCCS.ARPA>


  If this keeps up, we're soon going to have "Life" games in which C
programs are the cells.  Each one dropping little copies of itself all over
memory until they take over the whole system.  Mutants will spawn FORTRAN
and Pascal and Modula-2 and (god forbid) Ada programs that go thru several
half-lives until they return to normalcy.  "Queen bee" programs will also
start cc's in the background and the whole system will quickly grind to a
halt, unless a oscillating, semi-stable pattern is reached. 

AdamM

----------

"Generally speaking, the Way of the warrior is resolute
acceptance of death."  --  Miyamoto Musashi, 1645

In Real Life:  Adam S. Moskowitz
Working for:   BBN Communications Corporation
ARPA:          adamm@bbnccs	(also CSNet)
UUCP:          ...!{decvax, ima, linus, wjh12}!bbncca!adamm

/* Insert necessary (excess?) legal verbage (indentifying    */
/* tm's, promising all views expressed are mine, etc.) here. */

gnu@sun.uucp (John Gilmore) (08/30/84)

The ultimate here would of course be a program which could take
another program as input and produce a third program which at random
would be either a modified version of itself, or a modified version
of the program it read as input.  Of course, once in a while an alpha
particle will introduce a small change in the program.  It's a good
thing there are lots of small systems without parity, else evolution
would proceed much more slowly.

steven@mcvax.UUCP (Steven Pemberton) (09/03/84)

> 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(
  (s%1000=e|0|s),5)+a[15:33]+2*a[33:]))";s:=(s*9+7)%*100000;
  print(2*(a[:9]+whole((s%100=e|0|s),-5)+a[15:33])+2*a[33:]))

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.