131

Atari Puzzlements

Embed Size (px)

DESCRIPTION

atari basic book

Citation preview

Page 1: Atari Puzzlements
Page 2: Atari Puzzlements
Page 3: Atari Puzzlements

ATARI®hr theArari'home computer

by HERBERT KOHLillustrations by C. MICHA

A Creative Pastimes BookReston Publishing CompanyA Prentice-Hall CompanyReston. Virginia

Page 4: Atari Puzzlements

Library 0' CODlra. C.Wo.... iD PabUe.U.. D.taKohl, Herbert R.Atari puzzlements for the ATARI home computer.

"A Reston Computer Group book."1. Computer games. 2. Puzzles. 3. Atari computer--

Programming. 4. Basic (Computer program 1anguage)--Studyand teaching. I. Title.GV1469.2.K63 1984 794.8'2 84-3259ISBN 0-8359-0113-2

Interior design and production by Laura Cleveland.

This book is published by Reston Publishing Company which is not affilitated withAtari, Inc. and Atari is not responsible for any inaccuracies. ATARI is a registeredtrademark of Atari, Inc.

Copyright @ 1984 by Reston Publishing Company, lnc., A Prentice-Hall Company,Reston, Virginia 22090.

All rights reserved. No part of this book may be reproduced in any way or by anymeans without written permission from the publisher.

10 9 8 7 6 5 4 3 2 1

Printed in the United States of America.

ii

Page 5: Atari Puzzlements

ContentsIntroductionError PuzzlesSingle Line ScramblesLine Number ScramblesMissing Line PuzzlesControl Graphics PuzzlesAppendix: Planning Sheets

1727476989115

iii

Page 6: Atari Puzzlements
Page 7: Atari Puzzlements

IntroductionMost computer puzzles are versions of ordinary word games, such ascrossword puzzlesor anagrams,that draw their vocabulary from the worldof computing. The puzzles here are different. They provide games. amuse-ments, and challenges from within the world of computing itself andrequire some familiarity with Atari BASIC. The puzzles in this first volumeare quite simple; however, we plan additional volumes with more complexand sophisticated puzzles. You do not have to be a computer buff or askillful programmer to solve them. In fact, they would be an ideal comple-ment to any text or reference manual for a person of any agewho isjustleaming BASIC and is beginning to feel the power of creating programs.

We havenot includedany PEEKs or POKEs in the puzzlesand havenotusedprograms longer than 15 lines.Thesepuzzlesare designed to helpyouthink in BASIC. learn to read a program, and understand something aboutprogram structure. All the commands in the book are includedin the ATARIBASICReference Manual or in any introductory text on BASIC. Since theprograms are not that long or complex (though some are tricky and noteasyto solve automatically), many can be done with a paper and pencil. Infact, it's a good idea to try to think through many of these problemswithout using your computer. Program design is a mental activity that iscomputer-assisted and working on computer problems without using acomputer can help develop that skill. In order to help you sketch outsolutions, we've provided some formats designed to help with problemsolving. They are in the Appendix to the book and you should feel free tocopy them.

There are five different types of problems in the book: Error State-ment Problems. Line Scrambles, Line Number Scrambles. Missing CodeLines. and Control Character Graphics Design Problems. Some of the pro-grams deal with numbers; others deal with words. Color and graphics areoften used.The programs havebeenselectedto illustrate certain aspects ofAtari BASIC such as nested loops. subroutines, branching, and the mix ofgraphics,words. and numbers. You might even find it useful to incorporatesome of the smaller programs into larger programs you build yourself.

The answers to the programs will provide explanations of what theprogram does and give hints that might help you solve other problems.They will also give you a correct program. Remember. however. thatoften there is more than one correct answer and. if you feel correct.

1

Page 8: Atari Puzzlements

run your program. If it works you have come up with anothersolution!!

Here is a simpleexample that should giveyou a sense of the differenttypes of puzzles in the book:

10 PRINT NON A SCALE OF 1 TO 10N20 PRINT "HOW DO YOU FEEL TODAY?"30 PRINT Hl IS MISERABLE,10 GREAT"40 INPUT Xso IF X>:5 THEN PRINT "HAVE FUN! ":END60 PRINT "MAYBE THIS WILL HELP•• ":FORX-l TO 400:NEXT X70 BRAPHICS 7: COLOR 1eo PLOT 0,090 DRAWTO RND(1)*1:59,RND(1>*80100 BOTO 80

This programasks howyou feelon ascale of 1 to 10. 1 being misera-bleand 10 great. If you answer with anumberabove 5 the computerprints..HAVE FUN!" and the programends. If you answer 5 or less and indicateyouarenot feeling too great.the computergoes into aGraphics mode(line70) and draws an unending series of rays of different length emanatingfrom the upper left of the screen (point 0.0). It gives the appearance of asun and tries to cheer you up.

To let you know what a program is supposed to dowe have providedscreen pictures or. as they are usually called. screendumps to illustrate theprogramasit is supposed to run.Here are two screen dumpsofthe sampleprogram:

READYRUNON A SCALE OF TOHOW DO YOU FEEL TODAY?IS GREAT

HAVE FUN!READYRUNON A SCALE OF TOHOW DO YOU FEEL TODAY?IS GREAT

?5MAYBE THIS WILL HELP ..•

2

Page 9: Atari Puzzlements

Thisprogram can also illustrate the natureof differentpuzzle types inthis book.

Error Puzzles

In these puzzles, there will besome error for you to figure out. It could beon line 90, for example, which would then read:

so e rro r (1) *153; (1) *8(2l

Theerror would bethe; between 159 and the second RND. It shouldbe a , or the program wouldn't work.

Here's another possible error. Can you figure it out?

30 error PRHH"l IS GREAT

You probably guessed that the error was the missing" at the end ofthe line.

Single Line Scrambles

In these puzzles, one line is all scrambled up.You have to unscramble it tomake the program work. Here's a scramble of line 50:

50 er-r-or PRINT 5 THEt<J >'>" Dol[) IF HAVE

3

Page 10: Atari Puzzlements

The screen dumps will giveyou the clues needed to unscramble theline and make the program work.

Line Number Scrambles

Instead ofjust scrambling a linethese puzzles mix up all the linenumbers.You have to renumber each lineto put the program in orderand have it runas planned. This requires some thought and experimentation and it is herethat you are likely to find more than one correct unscrambling of aprogram.

A very simple scramble wouldjust reverse all of the line numbers sothat

line 10 becomes line 100line 20 becomes line 90line 30 becomes line 80

etc.

However. you arenot likely to come upon such patterned scrambles.The line numberpatterns do not provide hints to the unscrambling of thelines. You have to think through to the program structure to solve thepuzzle.

Missing Line Puzzles

In this variantof program puzzles, onelineof code ismissing. It might beinour sample:

40

or

80 PRINT

...... ????? ?"? ?'(???? ....... . . . . . . . . . . . .

...... ???????????'?? -r. . . . . . . . . . . . .

PRINT "????????????T is the indicator of the missing code line.That does not mean that PRINT.", or? necessarily appear on the missingline.

4

Page 11: Atari Puzzlements

Control Graphics Puzzles

In addition to its usual graphics modes your Atari has a control charactergraphic set. You can get this set by holding down the control (CTRL) keyand pressing any of the keys. (Consult your ATARI BASIC ReferenceManual for a diagram of the Control Graphics Keyboard).

These characters can be combined to make interesting patterns anddrawinqs. Theycan also beused within your program. Here's a short pro-gram that produces a fancy design using control character graphics:

I I I I ..................... ;•

Thepuzzles provide various challenging patternsfor youto reproduce,fill in, or reconstruct. Here are some samples using the little program above:

5

Page 12: Atari Puzzlements

Nowthat you have a sense of the kinds of challenges in this book. tryyour hand at solving them. Each section begins simplyand then moves onto more complex demands. Theanswers and their explanations are at theend of each chapter. Hope you have as much funsolving the puzzles as I hadinventing them.

6

Page 13: Atari Puzzlements

ErroPuzz les.orgettlpgxour program10dowhat you plan

7

Page 14: Atari Puzzlements

One of the most frustrating things about learning to program acomputer is that you can work hard at a program and make a tiny

mistake that throws the whole thing off. It is particularly annoying if youhave not internalized the programming language you are using. This firstsection contains some puzzles that embody the simplest mistakes every-body makeswhen learningto program. These mistakes shouldbe looked atas puzzles to solve rather than as signs of your inability to mastercomputing.

8

Page 15: Atari Puzzlements

1A SIMPLE CRYSTAL BALL

This program asks whetheryou like the number3 or 4 better. When run.this is how it is supposed to respond:

READ""RUNWHICH NUMBER I5 YOUR FAVORITEOF THE5E THO' 3 OR 4 ?0'4""OU ARE DEEP AND INIUITIVEREA!} ....•

However. your program simplybombs when you input the number3.It seems OK if you input 4:

READ""RUNWHICH NUMBER I5 ""OUR FAVORITEOF THE5E TWO: 3 OR 4 ?'":?4""OU ARE DEEP AND INTUITIVEREAD""•

9

Page 16: Atari Puzzlements

Here is the program. What is the mistake?

10 PRINT "WHICH Nl/I'IBER IS YOUR FAVORITE"20 PRINT "OF THESE TWO: 3 OR 4 7"30 INPUT X40 IF X-3 THEN BOTO 1010SO IF X-4 THEN BOTO lSOO1000 PRINT "YOU HAVE I1YSTI CAL POWERS."1010 ENDlS00 PRINT "YOU ARE DEEP AND INTUITIVE"lS10 END

10

Page 17: Atari Puzzlements

---2---NOT ENOUGH SUN

In this program. the intent was to have a full sun as in this screen dump:

Instead you got this on the screen:

11

Page 18: Atari Puzzlements

How could you change this program to give you the full sun?

10 GRAPHICS 7: COLOR 120 PLOT BO,4030 DRAWTO40 BOTO 20

12

Page 19: Atari Puzzlements

---3---COUNT DRACULA

You write a simple program asking your friend's name. You want thecomputer to tell your friend that he or she is a nice person. One of yourfriends decides to play around and type in Count Dracula and here is whathappens with your program:

10 PRINT "WHAT IS YOUR NAI'IE?"20 DIM A. (10)30 INPUT A.40 PRINT "YOU ARE A NICE GENTLE PERSON"so PRINT A$

WHAT IS YOUR NAME?GENTLE PERSON

COUNT DRACREADY•

How canyou fix your program so that it gives Dracula his full compli-ments like this?

13

Page 20: Atari Puzzlements

14

Page 21: Atari Puzzlements

---4---ALL I WANT IS A SQUARE

You try to drawa square in Graphics 7 and instead you get the following:

10 GRAPHICS 7: COLOR 120 PRINT "HERE IS A SQUARE"30 PLOT 40,4O:DRAWTO 60,4040 DRMlTO 60,60: DRMlTO 60,40so DRMlTO 40,40

So you try to modify the program and you get:

10 BRAPHICS 7:COLOR 420 PRINT "tERE IS A SlillIARE"30 PLOT 40,40: DRANTO 60,4040 DRAWTD 60,60: DRAWTO 40,60eo DRMlTD 40,40

15

Page 22: Atari Puzzlements

All you really want is this:

How do you do it and what went wrong with the other twoprograms?

16

Page 23: Atari Puzzlements

---5IN FIVE YEARS

This simpleprogram is supposed to aska person's age and then tell themhow old they will be in five years. It should run like this:

HOH OLD ARE YOU??t.2IN FIVE YOU HILL BE.17

READV•

Instead it runs like this:

17

Page 24: Atari Puzzlements

Here's the program. Where's the error?

10 PRINT "HOW OLD ARE YQlJ?"20 INPUT A30 PRINT "IN FIVE YEARS YOU WILL BE"40 PRINT X+l5

18

Page 25: Atari Puzzlements

---6---FILLING THE SCREEN

This is a reverse puzzle. Here is a program that will progressively fill thescreen up from top to bottom and left to right.

10 GRAPHICS 7: COLOR 120 FOR X-1 TO30 FOR V-1 TO 8040 PLOT X,Vso !'EXT X60 NEXT V

Now here is a screen dump of the program stopped in midcourse. If itwere left running the whole screen would be full.

Now hereare two screen dumps of programs that almost do what thefirst program does. A simple error, however. leads to a totally differentstructure on the screen. Notice that these programs lead to ERROR state-ments. Can you redo the correct program above to create these twoERROR statements and their associated screens?

19

Page 26: Atari Puzzlements

Error 6A

Error 68

20

Page 27: Atari Puzzlements

Answers-------1At line40 you instructedthe program to GOTO line 1010 which ended theprogram. You always have to be careful that your referyour program toexactly the lines you want. and it makes sense to check all GOTO state-ments if you have aprogram that doesn'trun properly. Here's the programwith the intended reference:

10 PRINT "NHICH NUI1BER IS YOUR FAVORITE"20 PRINT "OF THESE TWO: 3 OR 4 ?"30 INPUT X40 IF X-3 THEN 8OTO 1000so IF X-4 THEN 8OTO1000 PRINT "YOU HAVE MYSTICAL POWERS."1010 END

PRINT "YOU ARE DEEP AND INTUITIVE..END

---------2--------Theproblem was at line30. You only used half the screen. You have to becareful about the screen dimensions of the Graphics modes you are pro-gramming in. At line 30. the number40 should be80 as in this program:

10 GRAPHICS 7: COLOR 120 PLOT 80,4030 DRAWTO40 BOTO 20

21

Page 28: Atari Puzzlements

--------3--------Here is a program that will give Dracula his due:

10 PRINT "WHAT IS YOUR NAI1E?"20 DII'I A*<:r.5)30 INPUT A*40 PRINT "YOU ARE A NICE GENTLE PERSON"

Notice that at line 20 the DIM A$(10) has been changed to DIMA$(25). When you are storing words in Atari BASIC it is very important tomake sure that you make your dimension statement large enough tocontain the largest response you expect. The program. as changed forDracula. wouldn't work if your friend's name was John Wellington SmithFrankenstein. Sometimes it makes sense if you are not writing too long aprogram to overdimension your variables in order to anticipate your friends'tricks. DIM A$( 100) couldn't hurt in this case.

---------4 --------Here is the program:

10 GRAPHICS 7: COLOR 120 PR INT "HERE IS A SQUARE"30 PLOT 40,40: DRAWTO 60,4040 DRAWTO 6O,60:DRAWTO 40,60so DRAWTO 40,40

In one case. you made mistakes with the coordinates you drew. It isoften useful to sketch out a drawing on graph paper before trying to putcoordinates in a program.

In the other case. you used COLOR 4 in your program. If you look inyour Atari reference manual you'll see that the number 4 doesn't work withthe COLOR command and so nothing happened. It's important to playwithCOLOR and to PLOT around to get familiar with your Graphics 7 screen.

22

Page 29: Atari Puzzlements

--------5 --------10 PRINT "HOW OLD ARE YOU?"20 INPUT X30 PRINT "IN FIVE YEARS YOU WILL BE"40 PRINT

Notice that in the error program you INPUTA and then added+5. However.there was no X to add anything with andyour variablesdid not agreeso thecomputer printed 5 no matter what age was entered. When line 20 waschanged to 20 INPUTX the program worked. It is essential to checkall ofyour variables and see that they are properly referenced to eachother. Thisis a basic principle of programming.

--------6--------SA:

10 BRAPHICS 7:CDLOR 120 FOR X-1 TO 8030 FOR Y-1 TO40 PLOT X,Y:50 IIEXT Y60 IIEXT X

Error 141 saysthat the cursor in the program is out of range for theprogram-that isyou havesent it off the screen and bombed the program.If you look at program 6A YOU'll seethat you plotted V (the row) to go upto 159 and it canonly go up to 80. Here is a good exampleof a nested looperror. The program works the following way:

1-Plot the first X2-Plot the first 159 V's3-Plot the second X4-Plot the first 159 Y's again5-Plot the third X6-Plot the first 159 Y's againetc. for 159 times through the loop.

23

Page 30: Atari Puzzlements

This program nevergets beyond the second step. It plots 1,V for y= 1to 80 giving you the line on the left of the screen. Assoon as it gets to thepoint 0,81 the cursor runs off the screen and you get the ERROR state-ment. It is essential to check the references of the points you plot in aprogram to be sure that they do not exceed the number of points in theGraphics mode you are using, especially in nested FOR/NEXT loops.

68:

10 GRAPHICS 7:COl.OR 120 FOR X-I TO lS930 FOR V-I TO 8040 PLOT X,Vso NEXT V60 NEXT X

This is another FOR/NEXT loop trap. ERROR 13 says that there is nomatching FOR statement for the last NEXT. This error is common enoughto have a built-in error detector for it. What happens in this program thatdoes not work is that:

l-you begin with X=l2-and Y=l3-and plot 1,1 and4-go to the next X and plot 2,15-and then go to the next X and plot 3.16-and plot 4,1 all the way up to 159,1

This givesyou the horizontal line at the top of the screen. Once thisline hasbeendrawn, the program bombs. It hasnoway to get to the NEXTY. The nested loops have not been ordered correctly. Whenever you nestloops in order to have two things working in conjunction, you have tostructure the loops so that the first loop beginsand ends the nesting, thesecond loop is second from the beginning and second from the end, etc.Nested loops are like sets of parentheses where each ( has to have amatching ). Here'show three nested loopswould haveto be structured towork:

10 FOR :<=1 TO 1020 FOR \'=1 TO 52

24

Page 31: Atari Puzzlements

:30 FOR 2=1 TO 540 do something in the program50 Z60 'I'70 !'JC<T ><

The orderin isXiZ and the orderout is ZYX. It isagood programminghabit to check for correct order in and out of nested loops. As you sawinour error program. if you don't do it the computer will automatically do itfor you. It won't fix the error. however, so it's best to check yourself.

2S

Page 32: Atari Puzzlements
Page 33: Atari Puzzlements

27

Page 34: Atari Puzzlements

Thepuzzles in this section consist of a short program with one lineallscrambled up.There isa screen dumpaccompanying each program so

that you can tell what the program is supposed to do. An ERROR state-ment marksthe scrambled linesoyou don't have to figureout whichistheproblem line. Before you begin, here is an example of scrambled andunscrambled lines:

Scrambled:

50 Er ro r 1 GIJ':::;UE: TIJ:

Unscrambled:

50 FIJR :<=1 TIJ 1(2):13 I]sUE: 5(l(l: t,jE:<T >:

28

Page 35: Atari Puzzlements

1MULTIPLICATION

We'll start with a simple rnultipticatlon program. As you can see from thescreen dump.the program gives youmultiplication problems. as well as anopportunity to try again if you get the wrong answer.

Here's the scrambled program:

10 PRINT "HERE" S A SII'IPLE I"IlJLT1PLICATION PRDBLEI'I"20 PRINT30 LET X-INT(RND(1)*10)40 LET V-INT(RND(1)*10)

PRINT X," TII'IES "'V," _It60 INPUT Z70 ERRDR- XVZ*THEN100IFBOTD-80 PRINT "TRV AGAIN":BOTD 60100 PRINT "BOOD BOINB! HERE" S ANOTHEREXAl'lPLE:"110 BOTD 10

29

Page 36: Atari Puzzlements

---2DOUBLE SUN

This is a graphics puzzle whichplots a double sun on the screen. Each suntakes a tum drawing its rays. resulting in this image on the screen:

Here is the scrambled program:

10 BRAPHICS 7: COLOR 120 FOR X-I TO so30 PLOT 40,4040 ERROR- lRND80) )RNDBO(DRANTO(*,*1so IIEXT X60 FOR Y-l TO so70 PLOT 120,40eo DRANTO RND( 1 ) *79+80, RND( 1 ) *SO90 IIEXT Y100 BOTO 20

30

Page 37: Atari Puzzlements

---3HOURS TO SECONDS

This simple program converts hours to seconds. It asks you how manyseconds there arein anynumberof hours. It wont askfor seconds in morethan 10 hours since the calculating getsboringat that point. Nevertheless.it could:

REAI>VRUNTHERE ARE 60 MINUTES IN AN HOUR.THERE ARE 60 5ECONI>S IN AN MINUTE.HOW MANY SECONI>S ARE THERE IN 7 HOUR'?12400NOT QUITE;.?2'5200ABSOLUTLE:V!REAI>V•

Here's the scrambled program:

10 PRINT "THERE ARE 60 I'1INUTES IN AN HOUR. "20 PRINT "THERE ARE 60 SECONDS IN AN 1'1INUTE."30 LET X-INT(RND(1)*10)+140 PRINT "HaN t1ANY SECONDS ARE THERE IN ".X." HOURS?"so INPUT Y60 ERROR- PRINT-THEN!END"6OABBOLUTELY60*IF*X":Y70 PRINT "NOT QUITE.": BOTD so

31

Page 38: Atari Puzzlements

---4TIMED CALCULATIONS

This program sees if you can do some simplenumbermanipulation undersome time pressure. It mixes rnurtiplication with simple additionbyaskingyou to add 1 to your times answer. Of course. anynumbercould beaddedand the challenge could bemade more complex:

Here is the scrambled program:

10 PRINT "CAN YOU CALCULATE QUICKLY?N20 PRINT NLET" S SEE."30 PRINT40 PRINT "WHAT IS•• Nso LET X-INT(RND(I)*SO)60 PRINT70 ERROR- .... "-N+"PRINT2XTII'ES) (l80 FOR Z-1 TO lSOO:NEXT Z90 PRINT100 PRINT N WHAT IS YOUR ANSWER?N110 INPUT Y120 IF Y-(2*X)+1 T.-EN PRINT "YOU GOT IT!!! !":END130 PRINT NTRY ABAIN.":aoTO 100

32

Page 39: Atari Puzzlements

---5A SIMPLE NUMBER GAME

This is a simple number comparison game for young children. It askswhether one number is greater than another. If you look closely at theprogram you'll seethat the computer will neverselect two equalnumbers.It teaches the use of < and >.

READYRUNHERE'S A SIMPLE NUMBER GAME:IS 10 GREATER OR LESS THAN 11TYPE > IF IT IS GREATER AND <LESS

?

Here is the scrambled program:10 PR I NT "HERE' S A S I I'IPL.E NUt1BER GA/'IE:"20 ERROR- -XRNDCINT)20 C+LET)*130 IF X-10 THEN SoTo 2040 PRINT nIS 10 BREATER DR LESS THAN "JXso DI" A.U)60 PRINT70 PRINT "TYPE > IF IT IS BREATER AND( IF IT IS LESS"eo INPUT A.90 IF X( 10 THEN SOTo 1000100 IF X>10 THEN SDTo 20001000 IF A.-">" THEN PRINT "YOU SOT IT": END1010 PRINT "SORRY. TYPE RUN AND TRY ABAIN IF YOU LIKE. ":END2000 IF A.-"(" THEN PRINT "YOU SOT IT": END2010 PRINT "SORRY. TYPE RUN AND TRY ABAIN IF YOU LIKE.":END

33

Page 40: Atari Puzzlements

X"',,60J*PRINT"TI£RE*MINlIT"IN"ARE"'24

6MINUTE/DAY CONVERSION

Here's aminute/day conversion program that tellsyou howmanyminutesthere are in any numberof days. It does not quiz you. but answers yourquestion instead:

THERE 4320 MINUTES IN 3DO YOU TO CHANGE THE NUMBER OF

HOIH MANY DAYS??-7

THERE 10080 MINUTES IN 7DO YOU TO THE NUMBER OFDAYS?"':?'NO

READY•

Here is the scrambled program:

10 PRINT "I£RE· S A PROGRAtt THAT WILL TELL"20 PRINT "YOU HOW t1ANY MINlITES THERE ARE IN"30 PRINT "ANY NUMBER OF DAYS."40 PRINTso PRINT "HOW t1ANY DAYS?"60 CLR70 INPUT X80 BOSUB SOO90 PRINT "DO YOU WANT TO CHANGE TI£ NUMBER OF DAYS?"100 DIM A.(3)110 INPUT A.120 IF A.-"YES" TI£N BOTO so130 ENDSOO PRINT:510 ERROR-ES*DAYS":520 RETURN

34

Page 41: Atari Puzzlements

---7---QUICK ADDITION

Thispuzzle challenges you to add a string of sixnumbers together quickly:

READ ....•

Here is the scrambled program:

10 PRINT "HERE IS A LIST OF NUI1BERS"20 PRINT "TRV TO ADD THEtt TDBETHER tilUICKLV"30 FOR Z-l TO l000:NEXT Z40 DIM A(6):50 FOR X-l TO 660 ERRDR- AxeeeRNDINT)J»10.-70 PRINT AeX)," "'ao NEXT X90 FOR Z-l TO 2OOO:NEXT Z100 PRINT110 PRINT "WHAT IS VOUR ANSWER"120 INPUT V130 IFTHEN PRINT "VOU"VE BOT IT. ":END140 IF) THEN PRINT "TRV ONCE MORE.": BOTO 120

35

Page 42: Atari Puzzlements

---8---DOT COUNTING

This is a dot counting game.

Here is the scrambled program:

10 BRAPHICS 7: CDLOR 120 PR I NT "HOW MANV DOTS ARE ON THE SCREEN?"30 LET40 LET ..so FOR V-1 TO X60 PLOT ..,4070 ERRDR- 5WW-LET+so NEXT V90 PRINT "VOUR BUESS?" ,100 INPUT Z110 IF Z-X THEN PRINT "EXACTLV!! !":END

120 PRINT "COUNT ABAIN ...... :aoTO 100

36

Page 43: Atari Puzzlements

9RIDICULOUS

This program can print the word "RIDICULOUS"-any number of times-perhaps a ridiculous venture but one whose structure is used in someprogramming contexts:

Here is the scrambled program:

10 PRINT -HOW TII'ES NOll..D YOU LIkE tE TO-20 PRINT -PRINT VOUR NAtE: OR ANY OTI£RNORD?-30 INPUT X40 PRINT -..-tAT NORD NOll..D YOU LIkE tETO PRINT -.X.- TItES?-:50 DI" A* (:50)60 INPUT M70 ERROR- -n01VFORso PRINT M. - -.90 NEXT V100 END

37

Page 44: Atari Puzzlements

10BARBER'S PARADOX

This little scramble is a version of the classical Barber's Paradox: There is abarber in a town who shaves all and only people in the town who don'tshave themselves. Does heshave himself?

I've taken the paradox to school you might say:

:::: .il::::::::::::::

:::::::::

::

Ii

:::::::::::::::::1::::::'"

:.. ..l,i,: i!jjllllj11 !ll1111111\11..... ...... :..... ............. :::::::::::::: :::::; ::: ::::: :::.:::::::: :::::::: ::::::;:;:; ::::; :;::;:::::::

N 0 0 xEt v A:; R s v ::W!i!WWWI!ili.PEOPLE WHO DON'T DO HOMEWORK FORTHEMSELVES.DOES JULIA DO HER OWN HOMEWORK??VESTHEN SHE DOESN'T DO IT.JULIA IS A KIND AND LOVELV PERSON.SHE DOES HOMEWORK FOR ALL AND ONLYPEOPLE WHO DON'T DO HOMEWORK FORTHEMSELVES.DOES JULIA DO HER OWN HOMEWORK??NOTHEN SHE DOES DO IT.JULIA IS A KIND AND LOVELV PERSON.SHE DOES HOMEWORK FOR ALL AND ONLYPEOPLE WHO DON'T DO HOMEWORK FORTHEMSELVES.DOES JULIA DO HER OWN HOMEWORK??

10 PRINT "JULIA IS A KIND AND LOVELV PER8ON."20 PRINT "StE DOES HOt£WORK FOR ALL AND ONLV"so PR INT "PEOPLE WHO DON" T DO HOI'IEWORKFOR"40 PRINT "TI-E"'SELVES."so PRINT "DOES JULIA DO HER OWN HOI'IEWORK?"60 CLR70 DI'" A.(3)80 INPUT A.90 ERROR- JO".THENBOTO"A.-DOESN"TIF"StEVES: PRINT"ITDOTI-EN100 IF A.-"NO" THEN PRINT "THEN SHE DOESN"T DO IT.":BOTO 10

38

Page 45: Atari Puzzlements

Answers

-------1

10 PRINT "HERE"S A SIMPLEON PROBLEI"IH20 PRINT30 LET X-INT(RND(1)*10)40 LET V-INT(RND(1)*10):50 PRINT Xt" TII"IES "tVt" -"60 INPUT Z70 IF Z-X*V THEN BOTO 10080 PRINT "TRV AaAIN":BaTO 60100 PRINT HBOOD BaINe! HERE" S ANOTHEREXAI1PLE:"110 BOTO 10

Asyou can see, line70 (the scrambled line)checks for correctanswersusing the variable Z which is the answer you input. If z=x*y then you gotthe programandaresent to line 100 for congratulations and a chance atanother example. If Z< > x*ythe programmoves to line80 whichsendsyou back to the problemyou missed. This little technique can be incorpo-rated in games whereyou want to give people many chances to answer aquestion as well as generate new questions.

-------- 2--------

10 BRAPHICS 7: COLOR 120 FOR X-1 TO :5030 PLOT 40,4040 DRANTO RND ( 1 ) *80,RND ( 1 ) *80:50 NEXT X60 FOR V-1 TO :5070 PLOT 120,4080 DRANTO RND(1)*79+80,RND(1)*8090 NEXT V100 BOTO 20

39

Page 46: Atari Puzzlements

The scrambled line 40 is a DRAWTO statement. one of the mostpowerful Graphics commands in Atari BASIC. It selects random points onthe left sideofthe screen (halfthe screen is approximately 80 columns longand 80 columns wide) and draws from the center point of that halfscreento the chosen random point. This double sun effect is a good way to dressup the ending of a game.

--------3--------

10 PRINT "THERE ARE 60 /'III\PJTES IN AN HOUR. "20 PRINT "THERE ARE 60 SECONDS IN AN /'III\PJTE. U30 LET X-INTCRND(1)*10)+140 PRINT "HOW I'IANV SECONDS ARE THERE IN ".X. u HOURS?":50 INPUT V60 IF V-X*60*60 THEN PRINT uABSOLUTLEV!u:END70 PRINT "NOT Ii1UITE. ": BOTO :50

The key to unscrambling this puzzle is to know that you calculate thenumber of seconds in an hour using the formula X (the number ofhours)*60*60 which is the conversion formula. This form of program canbe changed to ask about converting feet or miles to inches. meters tocentimeters, etc. It is a simple and generalizable form of a conversion quizprogram.

--------4--------10 PRINT "CAN YOU CALCULATE IiIlJICKLV?U20 PRINT "LET"S SEE."30 PRINT40 PRINT "WHAT IS•• •:50 LET X-INTCRND(1)*:5Q)60 PRINT70 PRINT uC2 TIMES u.X.") +1-"80 FOR Z-l TO l:500:NEXT Z90 PRINT100 PRINT " WHAT IS VOUR ANSWER?·110 INPUT V

40

Page 47: Atari Puzzlements

120 IF Y-(2*X)+1 THEN PRINT "YOU BOT IT!!!! ":END130 PRINT "TRY AGAIN. ":BOTO 100

Thisissimplyanunscrambling of the integerrandom numberfunctionin Atari BASIC. Many beginning programmers confuse RND( 1)*X. whichgives adecimal answer. with INT(RND( 1)*X) which gives an integer. Therearetimes when having integers isessential to agame or program. Also. it isimportant to pay attention to the placement of parentheses in the INTstatement. A simple mistake like INT(RND(1 ))*X can cause quite a mess.Try to figure out the differenteffects of INT(RND(1))*6 and INT(RND( 1)*X).What you will see is the result of the fact that INT(RND(1)) is always O.

-------510 PRINT "HERE·S A SII'IPLE NUMBER BAI'E:"20 LET X-INT(RND(1)*20)30 IF X-10 THEN BOTO 2040 PRINT "IS 10 GREATER OR LESS THAN "IXso DIM A.(1)60 PRINT70 PRINT "TYPE ) IF IT IS GREATER AND< IF IT IS LESS"eo INPUT A.90 IF X<10 THEN BOTO 1000100 I F X>10 THEN BOTO 20001000 IF A.-")" THEN PRINT "YOU BOT IT": END1010 PRINT "SORRY. TYPE RUN AND TRY ABAIN IF YOU LIKE.":END2000 IF M-"<" THEN PRINT "YOU BOT IT": END2010 PRINT "SORRY. TYPE RUN AND TRY AGAIN IF YOU LIKE. ":END

The key to unscrambling this is to figure out that there is only onevariable in this challenge. (2*X)+1 isthe majorpart of the reconstruction ofthe scrambled line. There arealso some syntactical tricks that have to bemastered to use the PRINT statement with variables. You can print avariable along with words or other numbers but variables do not go inquotes as in this line:

41

Page 48: Atari Puzzlements

1(2) F'Plt,·jT :<*','and in this more complex line:

10 'r';······=//;Z

Note that the =is not a variable and has to be enclosed in quotes.This program can bemodified for practice in the kind of calculations

that arecommon in beginning algebra. For example. it can take the form-

I'Jhat i:::' 2'7

--------6--------

10 PRINT "I£RE" S A PROaRAI'I THAT WILL TELL"20 PRINT If YOU HOW I'IANV /'IINUTES THERE ARE IN"30 PRINT "ANV NlJ/'IBER OF DAVS."40 PRINTso PRINT "HOW I'IANV DAVS?"60 CLR70 INPUT Xso aOSUB SOO90 PRINT "00 YOU WANT TO CHANGE THE NU/'IBER OF DAVS?"100 DI/'I A.(3)110 INPUT M120 IF A••"VES" THEN GOTO SO130 ENDSOO PRINTS10 PRINT "THERE ARE ",X*60*24," /'IINlITES IN .. ,x, .. DAVS"S20 RETURN

Line 510 combines calculation with printing and. like the previousconversion puzzle (number3). can beused to performmanydifferent typesof conversions. In unscrambling this, the thing to watch for is the place-ment of quotes and semicolons. A misplaced quote or semicolon can des-troy the entire program.

42

Page 49: Atari Puzzlements

--------7--------10 PRINT "I£RE IS A LIST OF NUl"lBERS"20 PRINT "TRY TO ADD TIEM TOETI£R QUIC1<LY"30 FOR Z-1 TO 1000: NEXT Z40 DIM A(6):50 FOR X-1 TO 660 A(X)-INT(RND(1)*10)70 PRINT A(X)," '"ao NEXT X90 FOR Z-1 TO 2OOO:NEXT Z100 PRINT110 PRINT "WHAT IS ANSWER"120 INPUT Y130 IFTl£N PRINT "YOU"VE BOT IT. ":END140 IF) TI£N PRINT "TRY ONCE 1'IORE.":80TO 120

This program makes use of a powerful aspect of Atari BASIC-thearray. A(X) is dimensioned on line40 to contain sixnumbers. The scrambledline 60 places a random integer between 0 and lOin each position. Thatway. lists of numbers can begenerated and used as in this program. Begin-ningand intermediate programmers should take advantage ofthe ability tostore and use lists that this function provides. For examples of the use ofarrays see yourAtari BASIC Reference Manualor look uparrays in atextif you are not already familiar with them.

--------8--------10 BRAPHICS 7: COLOR 120 PR INT "HOW MANY DOTS ARE ON TI£ SCREEN?"30 LET40 LET ...:50 FOR Y-1 TO X60 PLOT ",4070 LET80 NEXT Y90 PRINT "YOUR BUESS?" ,100 INPUT Z110 IF Z-X TI£N PRINT "EXACTLY!!! ":END

120 PRINT "COUNT ABAIN•••• II:BOTO 100

43

Page 50: Atari Puzzlements

The LET W=W+5 statement represents a very powerful self-incrementing process that is often used in computer programs. For exam-ple. a simple program

10 LET :>:=020 FOF' '/=1 TO

LET ><=><+1: PRHH :x:40 t\lEXT :x:

will give you all the numbers from 1 to 100. If line 39 were changed to

30 LET ><=><+2:PRINT xyou would get the numbers from 2 to 100 counting by twos. This cangiveyou great control over how to change the variablesin your programs. In thecase of the program in this puzzle, W=W+5 was used to draw points thatwere five points apart so that they would be seen asdistinct on the screen.

--------9--------10 PRINT -HOW t1ANY TII'ES WOlLD YOU LIKE I'E TO-20 PRINT -PRINT YOUR NAI'IE OR ANY OTt£RWORD?"30 INPUT X40 PRINT -WHAT WORD WOlLD YOU LIKE I'ETO PRINT -,x,- TII'ES?-:50 DIM A* (:50)60 INPUT M70 FOR Y-I TO Xeo PRINT M, - -,90 NEXT Y100 END

This is a scramble of the FOR statement of the FORINEXT loop usedin the program to producethe ridiculous repetition. Notice that the numberof times through the loop (the X variable) changes each time you run theprogram. Most beginning programmers use fixed loops like FOR X=1 TO59. but sometimes it is more useful to change the number of timesthrough the loop as the program is running.

44

Page 51: Atari Puzzlements

-------10-------10 PRINT MJULIA IS A KIND AND LOVELY PERSDN. M

20 PRINT MSI£ lXES I«JI'EWORI< FOR ALL AND ONLY"30 PRINT MPEc:Fl.E IilIiO DON" T DO HOI'ENORKFORM40 PRINT MTI-EI'I8ELYES. M:50 PRINT MDOES JULIA DO HERDWN HOtEWORK?"60 CLR70 DUt A.(3)80 INPUT A.90 IF A••IIYESM THEN PRINT MTHEN 91£ DOESN"T DO IT.H:BOTO 10100 IF A*-MNQII THEN PRINT MTHEN SI£ DOES DO IT.H:BOTO 10

The scrambled line 90 aswell as line 100 make the paradox continueuntil you are bored and shut down the computer. However. the linesillustrate a technique you canadd to many of the gamesand quizzes in thissection. It will allow them to run many times instead of ending after justone play. Here's a very simple example:

10 PRINT • ·WHAT NUMBER IS THIS"20 X =HH(RND(1)*20)25 PRINT ><30 INPUT V40 IF x =V THEN PRINT • ·GREAT" :GOTO 1050 IF X< >V THEN PRINT ··TRV AGAIN" :GOTO 30

4S

Page 52: Atari Puzzlements
Page 53: Atari Puzzlements

47

Page 54: Atari Puzzlements

Thepuzzlesin this section leave all the codein a program intact. All theydo is scramble the line numbers. These numbers are not scrambled

according to any pattern so there is no use trying to solve the puzzles bytrying to figure out a pattern for transforming the line numbers. You haveto pay attention to the screen dumps and try to put a program structuretogether that will do what the illustrations show.

Scrambling line numbers of even the simplest programs can destroythem. For example. take this two-line program:

10 PRINT "HO HO HO!20 GOTO 1(2)

This will fill the screen up with a jolly greeting. Reverse the line numbersand you get:

10 GOTO 1020 PRINT "HO HO HO!";

This program will lock up at line 10 and stay there until you press theBREAKkey. Nothing will happen. In the simplest way. this is an illustrationof the importance of program structure in BASIC. Now for the puzzles.

48

Page 55: Atari Puzzlements

1HERE COMES THE SUN

Thisprogram shines and letsusknowendlessly that the sun iscoming andfilling up the screen. Here is a picture of what the program does and ascrambled version of the program. Unscramble the program and. if youfeellike it, make it fancier.

10 FOR X-1 TO X20 BOTO 2030 BRAPHICS 7: COLOR 140 PRINT "I£RE Cot1ES THE BUN"'50 DRAWTO60 PLOT 0.0

49

Page 56: Atari Puzzlements

---2---THERE GOES THE DRUNK

This is a simple variant on Puzzle 1 that produces a completely differentresult. You should be able to think through the difference and reconstructthe program that ambles with the drunk.

10 DRAWTO RND(1)*1S9.RND(1)*BO20 BOTO 3030 PRINT "TI£RE BOES TI£ DRlN<".40 BRAPHICS 7: COLOR 1so FOR X-1 TO 100: IIEXT x60 PLOT 0.0

50

Page 57: Atari Puzzlements

---3APOETIC SCRAMBLE

Here is a little poem with some input about the weather. The input,combined with the poem. should help you reassemble the scrambledprogram.

WELL, WHETHER YOU LIKE ITOR WHETHER NOTLOUSY WEATHERIS THE ONLY KIND OF WEATHERWE GOT.READY•

10 PRINT A•• N WEATHERN20 PRINT NNELL. Wl-ETHER YOU LIKE IT"30 INPUT A.40 PRINT "IS THE 0Nl.Y KIND OF WEATHER":50 DIM A. (:50)60 PRINT NOR WHETHER NOT"70 PRINT nWE BoT.Neo PRINT90 PRINT NHOW IS THE WEATHER TODAY?"

51

Page 58: Atari Puzzlements

---4---WHERE AM 11

This program allows youto plot apoint onthe screen inGraphics 7 and seethe point on the screen. When unscrambled. it is a good way to becomefamiliar with the positions on the screen.

10 BOTO 2020 INPUT B30 PRINT "ROW (0 TO 79)"40 PLOT A,B:50 PRINT "COLlJ'IN (0 TO 1:59)"60 BRAPHICS 7: COLOR 170 INPUT A

S2

Page 59: Atari Puzzlements

---5A LITTLE DIFFERENT ORDER

Here is a scrambled program and what it does when you run it:

n j f1j f)1nnn !:::;;: ...,·,,"""R'UN""····

?56DON'T ASK ME HHV. PLEASEGIVE ME THO NUM8ERS TO ADD.THE ANSHER IS A GLORIOUS 56I AM CRAZY A80UT ADDING BUTTHANK YOU. THAT HAS DELICIOUS!?37FIRST NUM8ER-SECOND NUMBER-READV•

.............. ::::::::::;:;:::::::::::::::::;;:::;':;:::"""

Here is the scrambled program and a dumpof what the unscrambledprogram is supposed to do.What is the unscrambled program?

READV•

53

Page 60: Atari Puzzlements

10 INPUT X20 PRINT "DON°T ASK ME WHY. PLEASE"30 PRINT "GIVE ME TWO NUMBERS TO ADD."40 PRINT "THE ANSWER IS A GLORIOUS '" X+YSO PRINT "I AM CRAZY ABOUT ADDING BUT"60 PRINT "THANK YOU. THAT WAS DELICIOUS!"70 INPUT Y80 PRINT "FIRST NUMBER-",90 PRINT "SECOND NlJI'IBER-",

54

Page 61: Atari Puzzlements

---6CAN YOU COUNT?

This program picks a number and asks you what comes next.

10 PRINT "..-tAT NUI1BER COI'ES AFTER ", X20 IF Y<>X+1 THEN PRINT "TRY ABAIN. YOU CAN DO IT!!!"30 LET X-INT(RND(1>*11>40 IF Y-X+1 THEN PRINT "RIGHT ON! ! ! ": END:50 BOTO 3060 INPUT Y

ss

Page 62: Atari Puzzlements

7---NEXT LETTER

This program is supposed to ask what letter comes next in the alphabetafter one chosen by the computer. When scrambled. here is what it does:

Here is the scrambled program and a screen dump of it runningunscrambled:

?I)GUESS ""G""IN?ERIGHTRE""I)V•

56

Page 63: Atari Puzzlements

10 PRINT X."TH IN THE ALPHABET?"20 INPUT B.30 PRINT "GUESS AGAIN"40 PRINT "WHAT LETTER COI'ES ".SO IF A.(X.X)·B. THEN PRINT "RIBHT":END60 A....ABCDEFGHIJKLI'INOPQRSTUVWXVZ ..70 DI" B.(1)80 BOTO 7090 DI" A.(26)100 LET X.INT(RND(1)*26)+1

57

Page 64: Atari Puzzlements

---8---NAME NAME

This program in Graphics 2 asks for your name and then prints it out 12times in large letters, Graphics 2 is nice for bold statements. Here is whatthe program looks like on the screen and the scrambled version of theprogram. Put it together and print the names of your family and friends.(Joshua is my son's name.)

NICE NAME!OSHUA JOSHUA JOSHUAJOSHUA JOSHUA JOSHUJOSHUA JOSHUA JOSH

A JOSHUA JOSHUA JOSUA

10 PRINT .6.A.20 FOR Z-l TO 1230 DIM A. (:50)40 PRINT .6."WHAT IS YOUR NAME?":50 PRINT .6.A.......60 PRINT .6. "WHAT A NICE NAME!"70 NEXT Zeo SRAPHICS 2:COLOR 190 INPUT A.100 PRINT .6

58

Page 65: Atari Puzzlements

---9---MEDITATION

A screen dump can hardly capture this program which cycles throughall ofthe colors and luminances of the Atari computerwhile slowly drawing astarburst. The program keeps on changing but slowlyenough to allowyouto relax and look. Here's an inadequate black and white dump of theprogram as well as the scrambled program:

10 NEXT X20 DRAWTO30 PLOT BO,4040 BRAPHICS 2

BRAPHICS CLR60 PRINT "HERE ARE SotE COLORS FOR"70 BOTO 10so FOR V-l TO v90 SETCOLOR100 FOR X-l TO l50110 PRINT "MEDITATION AND RELAXATION"

S9

Page 66: Atari Puzzlements

10---AN OPTIMISTIC PSYCHIATRIST'S

PROJECTIVE TESTThistest asks you for a colorpreference. All the responses are in full colorand are positive because the psychiatrist that taught me the test neverfound aperson she didn't believe in.The black and white can'tshowyouthepassionate red. the skyblue, or the bright yellowbut yourAtari can. Try tounscramble the program and then add colorupon coloruntil you can makepositive statements corresponding to all the 128 colors and luminancesthat youcan controlon the Atari. Finding 128positive statements will be agood exercise in itself, whetheryou can unscramble the program or not.

THREE COLORS IS YOUR

BLUE YELLOW

READY•

.... OU AREPASSIONATE

60

Page 67: Atari Puzzlements

THE SKYIS THE LIMIT

YOU SHINE.....ITH JOV

10 PRINT .6'" WITH JOY"20 IF OS-8'* THEN BOTO 200030 POSITION 0,340 SETCOLDR 0,13,1450 PRINT .6'" THE SKY"60 GRAPHICS 270 DIM A.(10),8'*(10),C.(10),D.(10)80 PRINT .6'" IS THE LIMIT"9() END100 PRINT .6'" YOU ARE"1000 PRINT " RED BLLE YELLOW"1010 PRINT .6," YOU SHINE"

61

Page 68: Atari Puzzlements

1020 A.-"RED":B.-"BLlJE":C.-"YELLOW"1030 SETCDLOR 0,4,71040 POSITION 0,3

END2000 BRAPHICS 22010 PRINT ..FAVORITE ..2020 IF D.-A. THEN 8OTO 10002030 PRINT "Wl-tICH OF THESE THREE COLORS IS YOUR"2040 PRINT .6." PASSIONATE"

END3000 GRAPHICS 23010 IF D.-C. THEN BOTO 30003020 INPUT3030 PRINT3040 SETCDLOR 0, S, 7

POSITION 0,3

62

Page 69: Atari Puzzlements

Answers

-------110 GRAPHICS 7:COLOR 120 PLOT 0,030 DRAWTO40 PR I NT "HERE COI'IES THE SUN".so FOR X-1 TO X60 BOTO 20

In Graphics programs. especially those with GOTO statements andloops. which line the GOTO refers to and the position the Graphics state-ment playswithin the loop are essential. In fact, try this program with thefollowing simple line change and seewhat happens:

--------2--------

10 GRAPHICS 7:COLOR 120 PLOT 0,030 DRAWTO40 PR I NT II THERE BOES THE DRlJNI( II •

FOR X-1 TO 100:NEXT X60 BOTO 30

Compare the unscrambled version of this program with that of Puzzle1. Notice that, once again. a simple change in the reference of a GOTOstatement totally changes the nature of the program results.

63

Page 70: Atari Puzzlements

--------3--------

10 PRINT "HOW IS THE WEATHER TODAY?"20 DIM30 INPUT A.40 PRINTso PRINT "WELL, Wl£THER YOU LIKE rr-60 PRINT "OR III£THER NOT"70 PRINT A.," WEATHER"SO PRINT "IS THE ONLY KIND OF WEATHER"90 PRINT "WE BOT."

Almost any saying can be turned into a fun program using this form.Try an input to the following:

Too many X's spoil the Y.An X in time saves Y.Better X than Y.

--------4--------10 GRAPHICS 7:COLOR 120 PRINT "COLUt1N (0 TO 159)"30 INPUT A40 PRINT "ROW (0 TO 79)"so INPUT B60 PLOT A,B70 BOTO 20

After you understand how this program works. try to do it in thedifferent Atari Graphics modes. It is a goodway to becomefamiliar with thevariety of screens the Atari allows you to use in your programs.

64

Page 71: Atari Puzzlements

-------510 PRINT "I Aft CRAZY ABOUT ADDING BUT"20 PRINT "DON· T ASJ( ME WHY. PLEASE"30 PRINT "GIVE ME TWO NUl'lBERS TO ADD."40 PRINT "FIRST NlII'IBER-".:50 INPUT X60 PRINT "SECOND NUt1BER-".70 INPUT Y80 PRINT "THNoII( YOU. THAT WAS DELICIOUS!"90 PRINT "Tt£ ANSWER IS A GLORIOUS ". X+Y

Ofcourse. this program caneasilybe extended to multiplication. See ifyou can get a bit more complex and extend it to division so the answercomes out evenand to subtraction so the answer comes out positive. Thiswill require a few more lines of code guaranteeing these conditions.

--------6--------

10 LET X-INTCRND(1)*11)20 PRINT "WHAT NUt1BER COI1ES AFTER ". X30 INPUT Y40 IF Y-X+1 THEN PRINT "RIGHT ON!!!":END:50 IF Y<>X+1 THEN PRINT "TRY AGAIN. Yau CAN DO IT!!!"60 GOTO 30

Here are some interesting modifications:

Canyou tell me what 5 times X is?Can you tell me what 5 times X divided by 3 is? (In this case set theprogram up so that the answer comes out even.)

65

Page 72: Atari Puzzlements

---------7--------

10 DIM A*(26)20 A*-"ABCDEFGHIJKL/'INOPCiIRSTUVWXYZ"30 LET X-INT<RND(1)*26)+140 PRINT "WHAT LETTER COI'ES ",so PRINT X, "TH IN THE ALPHABET?"60 DIM B*(1)70 INPUT B*80 IF A*<X.X)-B* THEN PRINT "RIGHT":END90 PRINT "BlJESS AGAIN"100 BOTO 70

Notice that the alphabet is stored in this program in A$ which wasdimensioned to hold 26 letters: DIM A$(26). Also notice that the key tothe program is the powerful BASIC command A$(X.X) which allows you tochoose the Ath member of A$. This is used in many code and word pro-grams. In its more complex form it has two variables A$(X.Y) which willallow you to useall the members of A$ from X to Y. Thus. if A$ containedthe alphabet then A$(X.Y) could have X=2 and Y=5 as values. It wouldbecomeA$(2.5) and the command 10 PRINTA$(2.5) would result in thecomputer printing out:

BCDE

--------8--------

10 GRAPHICS 2:COLDR 120 PRINT .6,"WHAT IS YOUR NAME?"30 DIM A*<SO)40 INPUT A*so PRINT .6, A*60 PRINT *6' "WHAT A NICE NAME!"70 PRINT .680 FOR Z-l TO 1290 PRINT *6,A*," ",100 NEXT Z

66

Page 73: Atari Puzzlements

--------9--------

10 BRAPHICS 720 PRINT "HERE ARE SOt£ COLORS FoR"30 PRINT "MEDITATION AND RELAXATION"40 SETCOLOR 4,RND(I)*16,RND(I)*ISSO FOR X-I TO SO60 PLOT eo, 4070 DRAWTO RND(I)*IS9,RND(I)*80eo FOR Y-l TO 7S:NEXT Y90 NEXT X100 BRAPHICS CLR110 BOTO 10

Play with the Atari SETCOLOR command and Graphics can providebeautiful effects even for the beginning programmer. Try to change thecolors. the luminances. and the pauses that keep the color on the screen.(This is done with empty FOR/NEXT loops like FOR X=l TO 100:NEXT Xwhichisempty since it tellsyou to donothingduringthosecycles.) You canget pretty good at experimenting with these powerful ideas built into theBASIC of the Atari.

-------10-------10 DIM A.(10),B.(10),C.(10),D.(10)20 A....RED.. :B....BLUE .. :C....YELLOW..30 PRINT "WHICH OF THESE THREE COLORSIS YOUR"40 PRINT "FAVORITE ..so PRINT60 PRINT " RED BLUE YELLOW..70 INPUT 0.80 IF D••A. THEN BOTO 100090 IF o..B. THEN BOTO 2000100 IF D.-e. THEN BOTO 30001000 BRAPHICS 21010 SETCOLOR 0,4,71020 POSITION 0,31030 PRINT .6." YOU ARE"1040 PRINT .6'" PASSIONATE"10SO END2000 BRAPHICS 22010 SETCDLOR 0,8,7

67

Page 74: Atari Puzzlements

2020 POSITION 0,32030 PRINT .6," THE SKY"2040 PRINT .6," IS THE LIMIT"20:50 END3000 GRAPHICS 23010 SETCOLDR 0,13,143020 POSITION 0,33030 PRINT .6," YOU SHINE"3040 PRINT .6'" WITH JOY"30:50 END

Here are a few color character equivalents I've managed to come upwith:

orange-abundant and nourishingpink-shy but perceptivedark blue-deep and curious

68

Page 75: Atari Puzzlements

TMiSSingLInePuzzles

69

Page 76: Atari Puzzlements

In these puzzles. one line ismissing from the programs. Themissing lineis indicated bythe linenumberand the statement PRINT"???????????".

In choosing what lines to dropout. the mainconsideration was to leave outsome essential part of the program structure. The screen dumps shouldgive you enough of an idea of how the program runs to allowyou to thinkyour way through to the full program. If you come up with a line thatworksand isnot the one given in the answer, please write and let meknow.There are many ingenious ways to solve programming problems.

70

Page 77: Atari Puzzlements

1COUNTING BACKWARDS

This program asks you for anintegerand then counts backwards from thatnumberto 1 and prints out the list.

10 PR I NT "WATCH ME COUNT BACKWARDS."20 PRINT "WHAT NUMBER SHOULD I START FROM?"30 INPUT X40 FOR Z-1 TO X

PRINT X60 PRINT "????????????????"70 NEXT Z

71

Page 78: Atari Puzzlements

2PATTERN MAKING

This program prints out a pattern. Oneaspect of the pattern is left out foryou to figure out.

10 PRINT "HERE·S A EASY PATTERN TO PRINT WITH A COI'IPUTER."20 PRINT "TRY TO I'IAJ(E YOUR OWN PATTERNS"30 FOR X-I TO 7:50: NEXT X40 PRINT "?????????????????"so PRINT "XXX XX XXX ".60 aOTO 40

72

Page 79: Atari Puzzlements

3A GOOD DAY

This program asks you if it's a good day for you. Here are the responses:

READ VRUNIS THIS A GOOD DAV FOR YOU??VESSHARE IT WITH YOUR FRIENDSREADV•

73

Page 80: Atari Puzzlements

And here is the program with the missing line of code:

10 PRINT "IS THIS A aooD DAY FOR YOU?"20 PRINT ..?????????????..30 IIIPUT A.40 IF A••"YES" THEN PRINT "SHARE IT WITH YOUR FRIENDS":ENDso IF A••"ND" TI-£N aOTO 100100 GRAPHICS 7:COLOR 1110 PRINT "HAYBE THIS WILL MAkE YOU FEEL BETTER.....120 PLOT 1l59.BO130 DRAWTO RND(1)*1l59.RND(1)*BO140 BOTO 120

74

Page 81: Atari Puzzlements

-----4-----GUESS

This isa letter counting game. It flashes aword onthe screen andasks youto guess howmanyletters it has. You can count the letters but estimatingthe length of the word is more fun.

Here is the program with the missing line of code:

10 DIM A.(20),B.(20),C.(20)20 A.·"HOPEFUL"30 B••"INDEPENDENCE"40 C••"TROUBLE":50 PRINT "HERE ARE SOME WORDS TO STUDYFOR A FEW"60 PRINT "SECONDS. GUESS HOW MANY LETTERS ARE"70 PRINT "IN EACH WORD."80 FOR X-l TO 7:50: NEXT X100 PRINT "??????????????????"110 PRINT .6,A.120 PRINT "YOUR GUESS?"130 INPUT W140 IF W-LEN(A.) THEN PRINT "GREAT! TRY ANOTHER":FOR X.l TO 7:50:NEXT X:GOTO200

75

Page 82: Atari Puzzlements

IF W<>LENCA.) THEN PRINT "TAKE ANOTHER LOOK":FOR X-I TO 7S0:NEXT X:GOTO100200 GRAPHICS 2: COLOR 1210 PRINT .6,B.220 PRINT "VOUR SUESS?"230 INPUT Z240 IF Z-LENCB.) THEN PRINT "BREAT! TRV ANOTHER":FOR X-I TO 7S0:BOTO 3002S0 IF Z<>LENCB.) THEN PRINT "TAKE ANOTHER LOOK":FOR X-I TO 7S0:NEXT X:BOTO200300 BRAPHICS 2: COLOR 1310 PRINT .6'C.320 PRINT "VOUR BUESS?"330 INPUT H340 IF H-LENCC.) THEN PRINT "BREAT! VOU BOT ALL THREE":END3S0 IF H<>LENCC.) THEN PRINT "TAKE ANOTHER LOOK":FOR X-I TO 7S0:NEXT X:BOTO300

76

Page 83: Atari Puzzlements

---5NEXT LETTER

This program asks for a letter and then givesyou the next letter in thealphabet. It won't be tricked if you ask for the letter after Z.

READVRU'"GIVE ME A LETTER IN THE ALPHABETA"'D I'LL TELL YOU THE NEXT LETTER.DO ... ·T TRY TO TRICK ME WITH Z BECAUSEI'VE ALREADY LEARNED THAT IT IS THE

LETTE:R"?RTHE NEXT LETTER IS 5READY•

10 PRINT "GIVE ME A LETTER IN THE ALPHABET"20 PRINT "AND I"LL TELL YOU THE NEXT LETTER."30 PRINT "DON"T TRY TO TRICK ME WITH ZBECAUSE"40 PRINT "I" VE ALREADY LEARNED THAT ITIS THE"PRINT "LAST LETTER."

60 DIM A.(26),B.(1)70 LET A.-"ABCDEFGHIJKLI'INOPQRSTUVWXYZ"80 INPUT B.90 FOR X-1 TO 26100 PRINT "??????????????????????"110 NEXT X

77

Page 84: Atari Puzzlements

---6---THIRD LETTER

Here isa puzzle that uses the same concept as Puzzle 5.You should be ableto get this one more easily:

10 PRINT "WHAT IB YOUR NAI'E?"20 DIM30 INPUT A.40 PRINT "DID YOU KNOW THAT THE THIRD"

PRINT "LETTER IN YOUR NAME IB •• "t60 PRINT "?????????????????"

78

Page 85: Atari Puzzlements

---7---NEXT NUMBER

Recently you tried a "next letter" puzzle. Here is a next number puzzle:

READY•

10 PRINT "WHAT I\I..JI1BER CotES AFTER.... '20 LET X-INT(RND(l)*l00)+l30 PRINT X40 INPUT V:50 IF V-X+1 THEN PRINT "ABBOLUTELV!":END60 IF V<>X+1 THEN PRINT -TRV ABAIN••• "70 PRINT -??????????????????-

79

Page 86: Atari Puzzlements

---8CALCULATE

Here is a simple arithmetic challenge:

Here is the program for it with a missing line:

10 PRINT "PICK A NUl'lBER FROI'I 1 TO 20"20 INPUT X30 PRINT "WHAT IS 4 TItES THAT NUl'lBERMINUS 3?"40 INPUT Y50 PRINT "????????????????????"60 IF Y-Z THEN PRINT "YOU BOT IT!!":END70 IF Y()Z THEN PRINT "TRY AGAIN.....80 BOTO 40

80

Page 87: Atari Puzzlements

---9COMPARISON

This program generates two random numbers and asks you which is thelarger. It does not giveyouasecond chance but gives youanother probleminstead.

Figure out the missing line:

10 PRINT "HERE"S A REAL SIMPLE KATH SAtte:"20 LET30 LET40 IF X-Y THEN BOTO 20

PRINT "WHICH NUMBER IS LARGER"60 PRINT70 PRINT X."QR".Yeo PRINT90 INPUT Z100 IF Z-X THEN BOTO 1000110 PRINT "???????????????????"1000 IF X)Y THEN PRINT "RIGHT. TRY ANOTHER ONE":BOTO 201010 PRINT II SORRY TRY ANOTHER EXAl"lPLE":BOTO 202000 IF Y)X THEN PRINT "RIGHT. TRY ANOTHER ONEil: BOTO 202010 PRINT II SORRY TRY ANOTHER EXAMPLE":BOTO 20

81

Page 88: Atari Puzzlements

10DICE

Thisprogram setsup the computerto roll apair of dice and then gives youthe total of the two rolls. It can beincorporated into manygame programs.

1.

DIE 2: 3TOTAL: 4DO YOU WANT ME TO ROLL AGAIN??YESHERE'S MY ROL.E:DIE.!.: 5DIE 2: 3TOTAL: 6DO YOU WANT ME TO ROLL AGAIN??NO.

Fill in the missing line:

10 PRINT "I KNOW HOW TO ROLE DICE"20 PRINT "HERE"S MY ROLE:"30 LET X-INT(RND(1)*6)+140 LET Y-INT(RND(1)*6)+1

PRINT60 PRINT "DIE 1:",X70 PRINTeo PRINT "DIE 2:",Y90 PRINT100 PRINT "?????????????????????"110 PRINT120 PRINT "DO YOU WANT ME TO ROLL ABAIN?"130 CLR140 DIM A.(3)1:50 INPUT A.160 IF A.-"YES" TI£N BOTO 20170 PRINT "THAT"S ALL FOLKS.":END

82

Page 89: Atari Puzzlements

Answers-------110 PRINT "WATCH I'1E COUNT BACKWARDS."20 PRINT "WHAT NUMBER SHOULD I START FROI'I?"30 INPUT X40 FOR Z-1 TO X

PRINT X60 LET X-X-l70 NEXT Z

Themissing line decreases the size of X each time the program runsthrough the loop. You could count backwards by Z's, 3's, or any othernumber.

-------2

10 PRINT "HERE" S A EASY PATTERN TO PRINT WITH A COI'IPUTER."20 PRINT "TRY TO MAKE YOUR OWN PATTERNS"30 FOR X-I TO 75O:NEXT X40 PRINT "*** ** *** ".:50 PRINT "XXX XX XXX ".60 GOTO 40

It isveryeasy to makepatternswith yourAtarL In fact, one chapter ofthis book contains a whole series of moderately complex pattern puzzles.What you have to look for in makingpatterns is the arrangement of blankspaces as much as the placement of symbols. The ; is what creates acontinuous pattern across the screen and, since the linescrolls around, youwill often find patternsthat don't look at all likeyou expect them to. It isadelightful idleactivity to explore patternsat random and develop an intui-tive sense of how lines like these will look when repeated on the screen inan infinite loop:

83

Page 90: Atari Puzzlements

$$$$$ $$$$$xxxxx

vvv eee ]]] vvv

--------3--------10 PRINT "IS THIS ABOOD DAV FOR VOU?"20 DIM A.(3)30 INPUT A'40 IF A,-liVES" THEN PRINT "SHARE IT WITH VOUR FRIENDS":END

IF A.-"NQ" TI-EN BOTO 100100 GRAPHICS 7:COLOR 1110 PRINT "MAVBE THIS WILL MAKE VOU FEEL BETTER••• "120 PLOT 1:59,80130 DRAWTO RND(1)*1:59,RND(1>*80140 BOTO 120

The challenge here is to define the lower left-hand point of the Gra-phics 7 screen. Try to do the same program in other Graphicsmodes andseehow the modes differ. You can mix Graphicsmodes within a programand it is useful to explore them all in order to be able to choose the rightGraphics format for your programming purposes.

---------4--------

10 DIM A.(20),B.(20>,C.(20)20 A.-"HOPEFUL"30 B.... "INDEPENDENCE"40 C.-"TROUBLE"

PRINT "HERE ARE SOME WORDS TO STUDVFOR A FEW"60 PRINT "SECONDS. BUESS HOW MANV LETTERS ARE"70 PRINT "IN EACH WORD."80 FOR X-l TO X100 BRAPHICS 2:COLOR 1

84

Page 91: Atari Puzzlements

110 PRINT .6, A.120 PRINT "YOUR GUESS?"130 INPUT W140 IF W-LEN(A.) THEN PRINT "GREAT! TRY ANOTHER":FOR X-1 TO 1500:NEXT X:GOTO200150 IF W<>LEN(A.) THEN PRINT "TAKE ANDTHER LOOK":FOR X-1 TO 750:NEXT X:GOTO100200 GRAPHICS 2:COLOR 1210 PRINT .6JB.220 PRINT "YOUR GUESS?"230 INPUT Z240 IF Z-LEN(B.) THEN PRINT "GREAT! TRY ANOTHER":FOR X-1 TO 1500:GOTO 300250 IF Z<>LEN(B.) THEN PRINT "TAKE ANDTHER LOOK":FOR X-1 TO 750:NEXT X:GOTO200300 GRAPHICS 2: COLOR 1310 PRINT .6,C.320 PRINT "YOUR GUESS?"330 INPUT H340 IF H-LEN(C.) THEN PRINT "GREAT! YOU GOT ALL THREE":END350 IF H<>LEN(C.) THEN PRINT "TAKE ANDTHER LOOK":FOR X-1 TO 1500:NEXT X:GOTO300

This program usesGraphics2. a large letter print mode. The programalso usesa command you may not be familiar with but which is very useful:LEN(A$). This command gives you the length of a word or sequence ofletters stored in a string. Thus, if you DIM A$(50) and INPUTA$ as "THE",LEN(A$)=3. It can let you know how much room is left in a string. cancreate size-word relationships, etc. You will probably encounter it in manyprograms you copy from computer magazines.

-------5Here is the program to fill out:

10 PRINT "GIVE I'E A LETTER IN THE ALPHABET"20 PRINT "AND I"LL TELL YOU THE NEXT LETTER."

as

Page 92: Atari Puzzlements

30 PRINT "DON"T TRY TO TRICK I'IE WITH ZBECAUSE"40 PRINT "I" VE ALREADY LEARNED THAT ITIS THE"PRINT "LAST LETTER."

60 DIM A*(26).B*(1)70 LET A*-"ABCDEFBHIJKLMNOPQRSTUVWXYZ"80 INPUT B*90 FOR X-1 TO 26100 IF B*-A*(X.X) THEN PRINT "THE NEXTLETTER 18 ",A*(X+1.X+1)110 NEXT X

Themissing line involvesusinga function, A$(X,X) which givesyou theXth member of A$. It is more fully explained in the answers to otherpuzzles that use the same function. What you should note here is thatA$(X+l,X+1) givesyou the letter or symbol stored after X in A$. What doyou think you'd get from A$(X+3.X+3)?

--------6--------10 PRINT "WHAT IS YOUR NAME?"20 DIM A*(2S)30 INPUT A*40 PRINT "DID YOU KNOW THAT THE THIRD"

PRINT "LETTER IN YOU NAI'IE IS•• "'60 PRINT A*(3.3)

--------7--------10 PRINT "WHAT NlJ'IBER C0I'IE8 AFTER.... '20 LET X-INT(RND(1).100)+130 PRINT X40 INPUT YSO IF Y-X+1 THEN PRINT "ABSOLUTELY!":END60 IF Y<>X+1 THEN PRINT "TRY ABAIN••• "70 BOTO 40

86

Page 93: Atari Puzzlements

This puzzle dealswith setting up a loop to let a persontry to correct awrong answer. The reference of GOTO statements is essential to how aprogram runs. If you tried

the target number and. therefore, the correct answer would be changed. Itis useful to deliberately messup your own programs and see what happens.Sometimes you'll make interesting and useful discoveries. Other timesyou'll internalize ERROR statements and help yourself create bug freeprograms.

--------8--------10 PRINT "PICK A NUI'IBER FROM 1 TO 20"20 INPUT X30 PRINT "WHAT IS 4 TII'ES THAT NlJt1BERMINUS 37"40 INPUT Y

LET Z-4*X-360 IF Y-Z THEN PRINT "YOU GOT IT!!":END70 IF Y()Z THEN PRINT "TRY AGAIN.....80 GOTO 40

In this case. you have to figure out how to perform the calculationasked for correctly and then give its result a new variable name. Z. If youforget to use this new variable you won't be able to use the result of thecalculation in other parts of the program without doing a recalculation. Inmany programs. the introduction of new variablesto indicate the results ofprocesses or calculations is a convenient programming tool.

--------9--------10 PRINT "HERE"S A REAL SIMPLE MATH GAME"20 LET30 LET40 IF X-V THEN BOTO 20

PRINT "WHICH NlJI'1BER IS LARGER"60 PRINT

87

Page 94: Atari Puzzlements

70 PRINT X."OR".VSO PRINT90 INPUT Z100 IF Z-X THEN BOTO 1000110 IF Z-V THEN BOTO 20001000 IF X>V THEN PRINT "RIGHT. TRV ANDTHER ONE": BOTO 201010 PRINT " SORRY TRY ANOTHER EXAI'IPLE":BOTO 202000 IF V>X THEN PRINT "RIGHT. TRY ANDTHER QNE":BOTO 202010 PRINT " SORRY TRV ANOTHER EXAMPLE":BOTO 20

This is another puzzle in which you have to figure out the correctGOTO reference. Instead of sending you back to an earlier part of theprogram asmost of the GOTO puzzlesdid. this one sends you to the endofthe program. It is important to realize that the GOTO command canallowyou to jump all over your program.

-------10-------10 PRINT "I KNOW HOW TO ROLE DICE"20 PRINT "HERE"S MV ROLE:"30 LET X-INT(RND(1)*6)+140 LET Y-INT(RND(1)*6)+1:50 PRINT60 PRINT "DIE l:".X70 PRINT80 PRINT "DIE 2:".Y90 PRINT100 PRINT "TOTAL:".X+V110 PRINT120 PRINT "00 YOU WANT ME TO ROLL AaAIN?"130 CLR140 DIM A*(3)1:50 INPUT M160 IF M-"YES" THEN BOTO 20170 PRINT "THAT"S ALL FOLKS.":END

Line 100 lets you both add the total and print it out at the sametime.There are times when it is convenient to use the PRINT statement inconjunction with a computation. especially if you do not want to store theresult of the computation in any other part of the program.

88

Page 95: Atari Puzzlements

6ntrolGraphicsPuzzles

89

Page 96: Atari Puzzlements

The Atari computer has a control graphics keyboard that is invisibleunless you press the control keyCTRL andthen a letter. (Consult your

ATARI BASIC Reference Manual for a diagram of the Control GraphicsKeyboard.)

Theshapes on the CTRL keyboard can beused to makevery interest-ing designs and pictures. They can also be mixed with letters to makeborders and designs within your ordinary text. Theydo not need a specialGraphics command and print straight from the keyboard. They can also beembodied in PRINT statementsalong with numbers and letters and can bestored in dimensioned strings the way letters can. Here are a few simpleexamples of the way control character graphics programs work. Theyshould help familiarize you with their function and help you understandhow to solve the puzzles in this chapter.

Thefirst sample simply uses the combination [CTRL][.] to produce aheart which is used as a border around a declaration of love:

READYJ.0 PRINT··•••••••••••'''''•••••••ZO PRTNT". I LOVE YOU ."

PRINT". YES. I 1>0 ."40 PRINT·· ••••••••••''''' ••RUN•••••••••••••••••• I LOVE YOU •• YES I DO ••••••••••••••••••READY•

The second example uses the numbers 1. 2. 3. and 4 along with the[CTRL][.] character to produce a field of numbers followed by diamondsthat have the same value as the numbers. Notice that the whole program isjust two lines long.

90

Page 97: Atari Puzzlements

.. j;: i;;;;: l:)1 j[)!: 111 jjrIj]1;1jIi; jjII jlll 111 1)1] 1) 1)1\ 11)])) 1); 111)))! 1j ji! j [! [! [)!:!:1 [) [[ [ [i;i[j!i[ii: i: i: i: [1 i1 j;: i:i: j: j:'ie'···PRIM"';';'!.' .2 0 GOT 0 10 !:ii!ii!.Wi

•• 3 ••• "' ••••1. 2 •• 3 ••• "' ••••.1.• 2,")"',:,,•• 3 ••• "' ••••.1.. 2 •• 3 ••• "' ••••1. 2 •• 3,,"""···••• "' ••••1. 2 •• ;J ••• "' ••••.1.. 2 •• ••• ',';;;;"4 ••••1. 2 •• 3 ••• 4 ••••1. 2 •• 3 ••••, ••• "'''''''•.1.'" 2 •• 3 ••• "' ••••.1.. 2 •• 3 ••• 4.••••.1.. ,,,"",,2 •• 3 ••• "' ••••1. 2 •• 3 ••• "' •••• J..• 2 •• "':,.:,,3 ••• "' ••••1. 2 •• 3 ••• 4 ••••1. 2 •• 3 ••• """'"4 ••••1. 2 •• 3 ••• 4 ••••1. ,2:•• 3 ••• 4 •• '"''''''•• t .• 2 •• 3 ••• 4 ••••1. 2 •• 3 ••• 4 ••••.1..• '''''',,:2 •• 3 ••• 4 ••••1. 2 •• 3 ••• 4 ••••1. 2 •• ''''':'''••• 4 ••••1. 2 •• 3 ••• 4 ••••1. 2 •• •• ,,"'"''i::.

• 2.. 3 •••;:::;::

mml ... ,

The third program. which also consists of only two lines. uses combi-nations of control characters. The triangular shapeis made out of [CTRL]Hfollowed by [CTRL]J and the table-like shape comes from combining[CTRL]Q and [CTRL]E. Notice that the placement of spaces on line 10controls how the program looks when it runs. You might want to experi-ment with a few designprograms before trying to solvesome of the designproblems in this chapter.

;"c::::;;:;;;;:::,.:.::;:::;;:;;::::::::':::::::;:::;:;:;::::;::;:::::::::;:: ...,•.••.•.!•.•.• '•••10 PRINT ............20 GOTO 10

........ ..... ........

.::::':;,:::: :,:: j\\j\jj\\\\\\\1\\\\\\11 \\I\Illl!\1\I\I\II \1! Ii\1\\\1\\\j\\\\\\\\\\j\\ \::::::.,:...

The fourth program is a variant of the third. The table forms havebeenremoved to create a mountain range effect:

91

Page 98: Atari Puzzlements

J.O PRINT ...... ....2:0 GOTO _.0

READY•........ ";

Now for some control graphics problems. Use the [CTRL] characterchart and the sketch pad in the appendix to help you solve them if youhaven't memorized the control characters and don't happen to have acomputer available.

92

Page 99: Atari Puzzlements

1PLASTIC SURGERY I

Here is a face. perhaps not the most beautiful one in the world but never-theless one with character. Using [CTRL] graphics try to reconstruct it.

READY•

93

Page 100: Atari Puzzlements

-----2-----PLASTIC SURGERY II

Here's the same face scrambled up as well as the program that generatesthe scramble, Try to reconstruct the original face by reordering the linenumbers without looking at the answers to [CTRL] Puzzle 1.Theanswer tothis puzzle is exactly the same as the answer to Puzzle 1.

, , )> ii'ii ('I ......... I"""'V"///( ---;--- ')

READY•

94

Page 101: Atari Puzzlements

---3TITLE PAGE

This program asks for sorneone's name and then prints out a simple titlepage for a book. Construct a program that does this for any name input.

95

Page 102: Atari Puzzlements

--4to9DESIGN DECIPHERING

This is a series of [CTRL] character designs for you to decipher and try toreproduce. Remember that some of the characters are made up of combi-nationsof other characters. Also. the use of blankspacing isessential to getthe design. I suggest you do some sketching andexperimenting with com-binations of [CTRL] characters in the course of trying to reproduce thesedesigns. There isasketch pad in the Appendix which isareproduction of thegrid on the Graphics 0 screen which uses regular print as well as [CTRL]graphics.

[CTRL] Design 4: Almost Music

-;'-:.,"......... 1.., ... -. 1." 1.., ... --1." ....... 1....... -. l.r..l -. l.r..lL.l -.,..-.1. ........ ., --1. ., ... -.1.",.--:'-1'- ...1. ........ 1.., ... -. l." ...... l.., ... -.1. ..-''''---1.'''..1''''''' -.r.--1."'..I .... ., ...-.1. ,,....-.1. ................ .,,.0--1.

1"' ........... -. -.1. ............. .,,..-.1. ...."'II'" .-. 1.I"'..IL..1 -.,. .-. 1.1'" ........ ., -• 1.1"' .,,. .-. 1.1"' ,,. .-. 1."L-ll , -.1.r ... L..I , -.1. ............. .,r .-. 1. r ..l lL-l .,,. 1. ..IL..I '"1r .-.1. 1"' ........ .,,. .-. 1.1"' ,,. .-. l.r .....,,. .-. 1.1"'..1"'" ",. .-. 1. .,,.-. 1.1"' -.r ·-·'r -. - • .,,. ........ ., .,,. .-. 1.1'" ., -. l................ .,r.-.1. L..lI ... 1"'.-.1. .....""'---l."'..IL..II "'I -.1.I"" ... L..I -.,..-.1. ......... .,,.·-· L ........... '''---1.''IL-I -...1....... .-. ... .....

96

Page 103: Atari Puzzlements

[CTRL] Design 5: Dizzy Roads, Shaky Bridges

...:,:::::;:': ::::::::::::::::::::;;::::::: ..........;::::;;;:::::::::::::::::::::::::::::::::::::;::::::::::.. :::::;::: :::::iq:ii:: :!!::::::::::: ::: .

;::::;:nn :::::::::::::::::::: iii::::::::::::::::::::: :::::::::::::; .":::::::::::::::::::...................... ;::;:::::::::::::::::::::::::::::;;:;;; ii ::::.. ··

...........

.. . ::::1jiHp:::: ::::::::::::::....

[CTRL] Design 6: Stripes at Cross Purposes

.................. :; ,::::::::::;::: .

::::::::::::::::

!!II!llI!!!!!!!1

1111111111111111

::::::::

... nlj1m:::::::;;::::::::::::::::: ::::::::::::::::::::::::::::.::::: ....

:;:::::::::::;;:;;;::::::::: gn i iiiii r=:: ::::::: :::: ::. ...

97

Page 104: Atari Puzzlements

[CTRLl Design 7: Clear Cutting in the Mountains

.....,.,.,.,.,.,.,., r

"'I., ...... r-rr.,.,.,., rrrr

..,..,.,., 1"''' rr• .. .. ..... .. .. ...".,., r r r ...,.,.,., rrrr

.,.,.,.., rrrr"''''1' rl"'rr.,.,.,., rrrr-.,.,.,., rr rr

., .,.,.., rrr r..,..,.,., ... r r ...

., ""'1" r rrr.,.,.,., rrrl'".,.,,,., rr r-r

.,.,.,., .... ,. .. r

.,., rrrrrrrr....

[CTRLl Design 8: Fences and Roads

11111 III! 11111111!!II!I!!!iIj11l1l\ f1; 1j!;

98

Page 105: Atari Puzzlements

[CTRL] Design 9: Dense Environment

!); [! H[Hi i1Hij j

.........:;:::::' .....::::::::::::::::::::::::;

...::::: :':::::;;;;;:!!!!!!!! !!!!!1!!!1! ::::: ;;: :::::::................:::::::: :::::::

99

Page 106: Atari Puzzlements

10ALPHABET RECONSTRUCTION

Now that you've spent some time dealing with some fairly complicateddesigns, here's a simple alphabet to reconstruct. It doesn't use [CTRL]characters but does use the keyboard and the program structure of BASICin the sameway that the previous program did.

:::::;::::::::::

,

100

Page 107: Atari Puzzlements

11NUMBER GRAPHICS

Now that you've had a chance to relax, here's a slightly more complexproblem using a mix of [CTRL] graphics and numbers. Notice that thenumbers change in the design in a regular way. The program structure issomewhat different than the onesyou've seen before but the program isnot much longer.

101

Page 108: Atari Puzzlements

12---FINISH THE TABLE

Put the missing leg on the table using [CTRL] graphics. Of course. you'llhave to write the whole program for the table to do it.

I•••AuREADYPUT THE OTHER LEG ON THE TABLE

102

Page 109: Atari Puzzlements

13STORMY WEATHER

The sea is not calm tonight as you can see from the screen dump below.Under that is a puzzling sea, one that questions the very nature of calm-ness. Can you write programs for each of these screen dumps?

103

Page 110: Atari Puzzlements

14SYMBOL ADDITION

Here is a game using numbers and [CTRL] characters. Three symbolsrepresent numbers. You are asked to memorize the symbol/numberequi-valents and then doaddition using the symbols. It is a good memorygamethat can bemade quite complex. Write a program for this game.

ANOTHER TIME.GOT IT DOHN!

READV•

104

Page 111: Atari Puzzlements

1SSIMPLE ANIMATION

Here are two simple animations you can make with control charactergraphics. You can actually get quite complex with them. although. ofcourse. you won't be able to duplicate the work of Walt Disneyor GeorgeLucas. With Graphics 8. you might be able to get closebut here is a modeststick figure beginning. These two dumps show the repetitions of a figurethat moves up the screen while changing position and posture. See if youcan recreate the figures and have them move as in the screen dumps.

o!!-'-1......I I

--1-,I I

105

Page 112: Atari Puzzlements

Answers-----1 and 2-----

o REM CTRL8lJPRINT" >"'''v'''L£:(

J":.:.'50 PRINT" -- r--60 PRINT U • Ii

70 PR:[NT ":: L.=rf ii' .. ::

(."READY

)"'VZ/(..

( J::, i i. i ,-I, (."

o REM CTRL8lJPRINT "

1':30 PRINT "30 PRINT ""40 PRINT "'50 PRINT "60 PRINT "70 PRINT "80 PRINT "<;;>0 PRINT ..

PRINT "PRINT "

READY

Notice that there are two answers given, one that duplicates the faceexactly and a second that pushes the chin off at lines 100 and 110. Whenrun they will give you the exact same thing. The reason that answer 2seemspushed in is that your Atari automatically puts a space between theline number and the command following it. Since 10 to 99 haveonly twodigits, they line up. 100 and 110 have three digits so they push thecommand over one space. You have to back it up in your mind to recon-

106

Page 113: Atari Puzzlements

struct the image the program will run. This is important to rememberwhen you list and edit control character graphics.

-------3

o REM CTRL3UJ.0 DIM A$ (50)2:0 PRINT "WHAT IS YOUR NAME?"30 INPUT A$40 PRINT " ....---------------..,50 PRINT " •••••••••••••••••••••••60 PRINT". READ THIS BOOK BV: •70 PRINT " • •80 PRINT" ";A$·!jo0 PRINT ".. .."it: ::1:11.2:0 ENDREADV•

-----4 to 9Almost Music

II... • _ ..... II... ., r··;

READV•

107

Page 114: Atari Puzzlements

Dizzy Roads. Shaky Bridges

READY•

"1Iil!l!iili!!illiiiliililii!!iiil!!l!!i!!!ii!I!!!!il!!I!!!I!I!iiiiiiii!i!i!!!iiiliii!i!!iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiili!i!ili!il!I!I!!!!!,

Stripes at Cross Purposes

108

Page 115: Atari Puzzlements

Clear Cutting in the Mountains

Fences and Roads

109

Page 116: Atari Puzzlements

Dense Environment

o REM CTRL1.1.U.1.0 PR:tNT .......,..."........ ;20 GOTO 1.0READY•

-------10-------

{) REH CTRL1ZU.1.0 PRINT "Anc DE:Ffi HIJK LHNOP ";20 PRINT "ORS & TIJV ..... )( & VZ II;30 GO TO 1.0READY•

Notice that I usedthree lines in the program instead of two. Usingthe: at the end of lines 20 and 30 creates the continuity of the program.

110

Page 117: Atari Puzzlements

------11

o REM CTRL5U.1-0 FOR X=J.. TO J..O20 FOR Y=1. TO J..O30 PRINT .. t-+-t "; Y;40 NEXT Y50 NEXT X

READY•

Notice that the changes in the numbers throughout the program aredetermined by the nested FOR/NEXT loops. If you are not familiar withnested loops, it would be useful to trace the program step by step. Forexample, the X loop instructs you to print what is inside the Y loop 10times and then go back to the start and keep on repeating the Y loop 10full runs.

Once you understand this and trace it through you should be able touse nested loops in many different contexts.

-------12-------

This drawing problem can lead to dozens of others. Try to make upsome for your family and friends, and have them be as creative in drawingand challenging you as well.

111

Page 118: Atari Puzzlements

13

112

Page 119: Atari Puzzlements

14

GOT"YOUTIHE.":GOTO

...::±

180 FOR M=1 TO Z1'0 IF '1'=1 THEN PRINT200 IF '1'=2 THEN PRINT210 IF '1'=3 THEN PRINT220 NEXT M230 INPUT N240 IF THEN PRINT.....N! .. : I::ND2'50 PRINT "TRY ANOTHER

READY•

REM CTRL10 PRINT "I-HoRE' S AR GAME'"2030 LET AS= ..... :LET DS=,,+u:LET C$= ...........40 PRINT .. STUD .... THIS TABLE OF VALUES:"50 PRINT .. J....60 PRINT70 PRINT + 2"80 PRINT

PRINT .....:3 u

100 PRINT.110 PRINT "WI-lEN v OU HAVE THE TABLEORIZED 1 •

120 PRINT "PRESS 7".130 INPUT X140 IF X=7 THEN PRINT .......150 ERROR- LET160 ERROR- LET170 PRINT "HOW MUCH DO THESE ADD UP7··

113

Page 120: Atari Puzzlements

------15

......L.-1:7'''I I"

o REM CTRI...IU10 PRIN.. ..20 PRINT ..30 PRINT ..40 PRINT "50 PRINT5") PRINT60 FOR X=:.I. ro70 PRINT ..80 PR:INT ..")0 PRINT ..J.00 PRINT ..1.10 PR:I:NT.1.20 FOR I<="J.. 10J.30 GOTO .t.O

J..00:NIX1 X.."'-1::-' ../ v'

:too: "I-:XI x

..... ::::::..

::::::::::::...

..'1(.'"/ .....

J.OO:NEXT X

J.OO:NEXT X.."'-1::-' ..

/ ,

......L.-1:7' ..I I"

: : : :: : : : ; ; ; : : ; : : : : : :: ::::::::::::::::::;;::::;;::::::::;::::::::::::::::: ;;:; :::;:;:::;:::::: j f: i: j fif j ji j:f jjfj11 i 11 fji [f) i tt; j. l\ ttt [1. t ttttl\ ttttl tttll t .:' .:;; ::;::::::::::"O""'R'E'M""C'f'R'L'l.'f'"

.10 PRINT II

20 PRINT .."""""'''''' 30 PR:[NT "40 PRINT ..

50 PRINT"""""""" 5") PRINT60 FOR X=J. TO"""""""" 70 PRINT ..'i!:!'':.!.! gg ::::n:n ::J.00 PRINT ..

110 PRINTJ.20 FOR X=J. TO 100:NEXT XJ.30 PRINTJ.40 PRINT II150 PRINT ..J.60 PRINT ..170 PRINT ..J.80 FOR X=1 TOJ.")O GOTO J.0

The key structural elements of these programs could be described as:

PRINT Figure l-PAUSE TO SEE ITPRINT Figure 2-PAUSE TO SEE IT-GO BACK TO FIGURE 1

Teasing out the structure of programs in this way can help you createyour own programs or modify those other people design.

114

Page 121: Atari Puzzlements

......• I,,)• I

• I.,)• I

AppendixPlanning Sheets

These pages are designed to helpyou solve some of the problems in thisbook. They consist of a series of TV or monitor screens with room underthem to write lines of code. They can beused in manydifferentways andsome readers will certainly develop their ownaids to solve the puzzles. Hereare two examples of how they can beused for two puzzle versions of thissimple program:

10 PRINT "HOW OLD ARE 'lOU'?20 X30 LET V=1383- X40 PRINT "'r'OU WERE BORt'<l

Puzzle version 1:missing line of code

10 PRHH'·HOl>l OLD ARE 'lOU 7····20 INPUT >:30 PRINT "777777?777777"40 F'RHH''VOU WEF'E BORN IN

Puzzle version 2:scrambled line number version

10 I t'IPUT :<20 PRINT "HOW OLD AF'E VI]U?"30 PRINT "'iOU WERE BORN IN "; 'i40 LET V=1383-X

115

Page 122: Atari Puzzlements

Hew o tel ""e you?

10 PR, II How old «roe"

tiow old are 'Iou ?

?•

SClmf as

LET)(= 1'I8a-)C

116

10 PR. " How okl ClRyou

HDwold are ,/oo.??,

?----

Page 123: Atari Puzzlements

30 '/ YilfJ.r -old

Same abo'l(, +you. wan. born it) i

40 PR, " 'Iou. wue.bOr"t\ in "j Y

117

SOLUTiON

SaMe.'! eU we:re: be f1\ ..1'1

'" 0 you. wtf"ebort\ in; 'I

Page 124: Atari Puzzlements

118

Page 125: Atari Puzzlements

119

Page 126: Atari Puzzlements

SKETCHFOR

CONTROL GRAPHICSAND TEHT

120

Page 127: Atari Puzzlements

'"<"'l

N<"'l

0:>N

...N

aN

...

I

ao ...

121

aN

<"'lN

Page 128: Atari Puzzlements

NCD"'0o:EU)u:c0-f!c

I

I I I ;

I I I II

o

co

o

122

Page 129: Atari Puzzlements

123

Page 130: Atari Puzzlements
Page 131: Atari Puzzlements