Personal Computer News


A Program For Programming's Sake

Categories: Letter

 
Author: D. J. Pilling
Published in Personal Computer News #056

A Program For Programming's Sake

There is a computing problem which goes 'write a program whose sole effect, when run, is to print out a copy of itself'.

In the solution, you are not allowed to cheat by using machine dependent tricks like PEEKing the area where the program is stored or putting 'LIST' into the keyboard buffer.

The problem can be solved in any language though the actual method is likely to vary. You might like to pause and try to think of how you would solve the problem in your favourite computer language. A solution for BBC Basic is given in the listing below.

Note that A$ is 79 characters long.

10 A$="   10 A$=   20 PRINT MID$(A$,1,9)+CHR$34+A$+CHR$34+CHR$13+CHR$10+MID$( A$,10,70)"
20 PRINT MID$(A$,1,9)+CHR$34+A$+CHR$34+CHR$13+CHR$10+MID$(A$,10,70)

D. J. Pilling
Anchorsholm, Blackpool

D. J. Pilling

This article was converted to a web page from the following page of Personal Computer News #056.

Personal Computer News #056 scan of page 15

Page 15