Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!cmcl2!beta!hwe From: hwe@beta.UUCP (Skip Egdorf) Newsgroups: comp.lang.misc Subject: Re: Problems needed! Message-ID: <6835@beta.UUCP> Date: Thu, 25-Jun-87 23:37:36 EDT Article-I.D.: beta.6835 Posted: Thu Jun 25 23:37:36 1987 Date-Received: Sat, 27-Jun-87 04:39:45 EDT References: <9819@duke.cs.duke.edu> Organization: Los Alamos Natl Lab, Los Alamos, N.M. Lines: 58 Summary: the self-reproducing program In article <9819@duke.cs.duke.edu>, jds@duke.cs.duke.edu (Joseph D. Sloan) writes: > It's common practice in comparative programming languages > courses to assign the same problem in several different languages to > compare and contrast different features of those languages. > ... > > Would folks that have such problems or collections of such > problems be willing to share? Please describe 1) the problem, > 2) proposed languages, and 3) what langage features are being contrasted. > I will be happy to summarize mail to the net but I suspect this is > of general interest so replying directly to the net is appropriate. > Please folks, lots of problems! > > Many thanks, > jds@duke This might provoke some interesting discussion! At the point where students have had enough programming to understand the difference between engineering a solution to a problem and artfully composing a program for the fun of it, I would recomend the problem of the self reproducing program. For those who have not run into it, this problem is to write a program that, when run, prints its original text on its output. No fair opening the source file and copying it, the program must be totally self contained. The program is usually done by having a character string that is data, and is also a part of the program, and then cleverly printing the string two or three times, sometimes as data. e.g. in C something like char s = "char s %s ... main(){printf(s, s, ...)"; main(){printf(s, s, ...)} works. extra credit for the shortest, clearest, most obfuscated, etc. The problem is most easily done in C and Lisp (ok, my opinion.) and is doable in most others. Definitly try it in FORTRAN and PL/I. FORMATS work. BASIC and PASCAL will be difficult due to lack of compile-time initializations. This problem should not be used at the impressionable place where the students think that this is really the way to write programs. Leave it until they know both the engineering of and the art of programming. This problem is really a joy to play with in the ART side of the house. This problem seems to impress the young mind with a strong impression of which languages are true power tools for solving problems, and which are "more in the problem set than the solution set." I am not sure just which language features produce this feeling, but it is a very good problem for letting the students discover the fact that some languages try to get in your way more than others. Save the problem until they understand WHY you sometimes want the language to get in your way. Skip Egdorf hwe@lanl.gov