Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site cbscc.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!cbosgd!cbscc!lvc
From: lvc@cbscc.UUCP (Larry Cipriani)
Newsgroups: net.sources
Subject: Thompsons self reproducing program
Message-ID: <3457@cbscc.UUCP>
Date: Fri, 17-Aug-84 12:19:14 EDT
Article-I.D.: cbscc.3457
Posted: Fri Aug 17 12:19:14 1984
Date-Received: Sun, 19-Aug-84 02:30:15 EDT
Organization: AT&T Bell Laboratories , Columbus
Lines: 46

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