[net.sources] Thompsons self reproducing program

lvc@cbscc.UUCP (Larry Cipriani) (08/17/84)

In the August '84 issue of "Communications of the ACM" were
the Turing Award Lectures by Ritchie and Thompson [trademarks
of Bell Laboratories].  The article by Thompson showed how one
could write a program that when compiled and executed would
reproduce it's source.

I got it to work on our 3b5 and 3b20, and managed to make it
even smaller.  This program may require minor modifications on
other 32 bit machines, and will require major modifications on
16 bit machines.  The self reproducer is 325 characters long and
contains no excess whitespace.

As in Thompsons example, what is below is a program that
produces a self reproducing program (for ease of programming!).

int s[]={

'int ', '*p=s', ';pri', 'ntf(', '"int',

' s[]', '={")', ';whi', 'le(*', 'p)pr',

'intf', '("%d', ',",*', 'p++)', ';pri',

'ntf(', '"0};', 'main', '(){%', 's}",',

's); ', 0

} ;

main()
{
	int *p = s ;

	printf("int s[]={") ;

	while(*p)
		printf("%d,", *p++) ;

	printf("0};main(){%s}", s) ;
}

If anyone can come up with a self reproducer that is smaller
I'd be interested in seein it.  Have fun,

				Larry Cipriani
				cbscc!lvc

perl@rdin.UUCP (Robert Perlberg) (08/20/84)

<>

Why?

Robert Perlberg
Resource Dynamics Inc.
New York
philabs!rdin!perl

rees@apollo.UUCP (08/21/84)

Oh come on.  We've been through this before.  As far as I know, the shortest
self-producing program in C is the one submitted by Berry Kercheval at Zehntel.
It's 101 bytes.  Here it is:

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

prudence@trwrba.UUCP (Charles E. Prudence) (08/31/84)

Neither Thompson's "self reproducing" program nor the one submitted
by Larry is truly "self reproducing."  Both programs require external
data which is not reproduced.  The programs can be shortened by simply
copying their source files.  The challenge Thompson was referring to
is to write a totally self-contained program.

Any solutions?

                                Charles Prudence
.
..
w

B
A


k