Word's Worth #1

Type
Education
Category
Word game / string-handling tutorial
Author
Bob Albrecht and George Firedrake
Published in
ANTIC Vol. 1 No. 6 (February 1983), "DragonSmoke: Word's Worth, Part II"
Year
1983
Language
Atari BASIC
Requirements
Any Atari 8-bit, 8K RAM, Atari BASIC

About the program

Bob Albrecht and George Firedrake wrote DragonSmoke for ANTIC: a column of "problems for you to ponder, questions for you to answer, programs for you to write, and whatever other mischief we might cunningly contrive". In an earlier issue they had challenged readers to compute a word's "worth", the sum of its letter values with A=1, B=2 and so on up to Z=26. In February 1983 they published their own answer. Their samples: HOBBIT is worth 56, DRAGON 59 and WIZARD 81.

It is a tiny program, but a good model of clear beginner's BASIC. Each block starts with a REM on a line number that is a multiple of 100, so you can see the structure at a glance.

What you need

Any Atari 8-bit with Atari BASIC.

Typing it in

Plain ASCII, 22 lines. GR. 0 in line 120 is Atari BASIC's abbreviation for GRAPHICS 0. Type capitals when you use it. Lower-case letters fall outside the A–Z range and are ignored, just like punctuation.

How to use it

RUN it and type a word at the YOUR WORD? prompt. The program prints its worth and asks again. Spaces, hyphens, apostrophes and digits are skipped, so ISN'T is worth 62, FLIP-FLOP 92, and 123 is worth nothing at all. Press BREAK to stop.

How it works

  • Atari BASIC has no string arrays. WORD$(L,L) (line 520) takes the single character at position L and copies it into L$.
  • Lines 530–540 skip anything that comes before "A" or after "Z" in character order. ASC(L$)-64 then turns A–Z into 1–26, because "A" is ATASCII 65.
  • WW collects the total.

The column gave two more ways to write block 500. One compares ASC(L$) with 65 and 90. The other stores the code in LX and does both tests in a single line: IF LX<65 OR LX>90 THEN 570.

Variations to try

The authors set these challenges:

  • Word's Worth #2: multiply the letter scores instead of adding them (WIZARD = 387,504). They thought you would need to change only two lines.
  • Scrabble scores: replace the A=1…Z=26 values with the Scrabble tile values printed in the column (A=1 … Q=10, Z=10), for example with a lookup string or DATA. The column's sample: CAT scores 5 and AZTEC 16.
  • With a dictionary to hand, find a word worth exactly 100.

Listing

100 REM ** WORD'S WORTH #1
110 DIM WORD$(50), L$(1)
120 GR. 0
200 REM ** ASK FOR A WORD
210 PRINT: PRINT "YOUR WORD";
220 INPUT WORD$
300 REM ** COMPUTE LENGTH OF WORD
310 WL = LEN(WORD$)
400 REM ** START WORD'S WORTH AT ZERO
410 WW = 0
500 REM ** COMPUTE WORD'S WORTH
510 FOR L = 1 TO WL
520 L$ = WORD$(L,L)
530 IF L$ < "A" THEN 570
540 IF L$ > "Z" THEN 570
550 LS = ASC(L$) - 64
560 WW = WW + LS
570 NEXT L
600 REM ** PRINT THE WORD'S WORTH
610 PRINT "YOUR WORD IS WORTH"; WW; "POINTS"
700 REM ** GO FOR ANOTHER WORD
710 GOTO 210

Credits