Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utcsrgv.UUCP Path: utzoo!utcsrgv!oscar From: oscar@utcsrgv.UUCP (Oscar M. Nierstrasz) Newsgroups: net.misc Subject: self-printing programs Message-ID: <2933@utcsrgv.UUCP> Date: Tue, 13-Dec-83 18:34:40 EST Article-I.D.: utcsrgv.2933 Posted: Tue Dec 13 18:34:40 1983 Date-Received: Tue, 13-Dec-83 19:29:32 EST Organization: CSRG, University of Toronto Lines: 29 Here's a puzzle! (Perhaps this belongs in net.jokes ...) What is the shortest program you can come up with whose only output is the program itself? Trivial solutions are not acceptable -- the null program will obviously do the trick. Similarly, it must not access any external text or data files since the shell script cat $0 simply reads and prints itself. Clearly all the "data" must be contained in the program itself. A shell script containing self where "self" is a shell script that does an "echo self" is also cheating. So far I have a three-line shell script that seems to fit the bill. Any takers for this mind-bender? Please *mail* me and I'll post the cleverest solutions after a decent wait. (Programs are fine, but shell scripts tend to be shorter.) Oscar Nierstrasz -- UUCP: { allegra cornell decvax decwrl floyd ihnp4 linus sask ubc-vision utzoo uw-beaver watmath } !utcsrgv!oscar