A puzzle: five 100-page books stand on a shelf and a bookworm eats in a straight line from the first page of the first book to the last page of the last book. How many pages did it eat? Type an answer; a wrong one asks again. The right answer brings up a top view of the books on the shelf, drawn with graphics characters, and the worm eating its way through them.
The puzzle is from Marilyn vos Savant’s column in the Sunday Oregonian of October 25 (1992). The program does not start by itself; the article suggests saving it with LINE 50. The second file has Jack Armstrong’s changes from the next issue, as printed: shelf ends, book numbers 1-5, a faster worm, and a colour line 45 printed without its colour numbers, which stops RUN with an error; start that version with RUN 50 (or GO TO 50), or put your own colours in line 45.
Published in The Plotter November 1992 (Bookworm); Jack Armstrong’s changes in December 1992 (More on Bookworm).
Source Code
40 REM BOOKWORM PROGRAM
45 REM DICK WAGNER
50 PRINT AT 0,0;"There is a set of 5 books on a shelf. Each book has 100 pages. A bookworm starts eating on the first page of the first book."
60 PRINT "From there the bookworm eats in a straight line through to the last page of the last book."
70 PRINT "Through how many pages did the bookworm eat?": INPUT p: PRINT : PRINT p: PAUSE 50: PRINT AT 10,0;" "
80 IF P<>302 THEN GO TO 50: IF P=302 THEN GO TO 90
90 CLS : PRINT AT 12,0;"CORRECT, 302 PAGES. HERE IS THE BOOKWORM AT WORK"
120 FOR n=65368 TO 65368+23
130 READ d: POKE n,d: NEXT n
140 DATA 130,254,254,254,254,254,254,254
150 DATA 254,254,254,254,254,254,254,254
160 DATA 254,254,254,254,254,254,254,124
200 PRINT AT 5,5;"A";"A";"A";"A";"A"
210 PRINT AT 6,5;"B";"B";"B";"B";"B"
220 PRINT AT 7,5;"C";"C";"C";"C";"C"
230 PLOT 0,108: DRAW 100,0
240 PLOT 0,140: DRAW 100,0
250 PLOT 0,139: DRAW 100,0
260 PLOT 0,138: DRAW 100,0
270 PRINT AT 0,0;"Top view of 5 books"
280 PRINT " on book shelf."
310 FOR X=45 TO (45+27)
320 PLOT 45,124: DRAW INVERSE 1;(X-45),0
325 PAUSE 50
330 NEXT XNote: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.





