BASIC CHR 205.5

From Maze

Current revision as of 14:36, 17 July 2011 by Nickm (Talk | contribs) (→How long is this program?)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
 10 PRINT CHR$(205.5+RND(1)); : GOTO 10

This is a one-line adaptation that uses the same method as the three-line version in the Commodore 64 User's Guide, which is from 1982 and is the earliest known published version of the program.

How long is this program?

Thirty-nine characters, as written above.

The C64 supports abbreviations for keywords -- "?" for "PRINT" and generally unshifted first letter shifted second letter for other keywords. You also don't have to use spaces in a C64 BASIC program unless you want to print a space. And, any line number, including 1, is as good as 10.

So if you type this on a C64, you'll input the program using only 22 keystrokes (plus the return that you need at the end):

 1?cH(205.5+rN(1));:gO1
 

(Note that "c" will appear as the uppercase letter "C" and "H" will appear as a |-like symbol. "N" will appear as /-like symbol that is output by the program.)

If you list this, the representation that is produced is 32 characters long:

 1 PRINTCHR$(205.5+RND(1));:GOTO1

Update, 17 July 2011: Actually it is possible to trim the compressed version by one character (21 characters long):

 0?cH(205.5+rN(1));:gO

Since "GOTO" by itself will jump to line 0. Also, "RUN" can be used instead of "GOTO," so that the expanded listing is a mere 30 characters long:

 1 PRINTCHR$(205.5+RND(1));:RUN

RUN is reported online to be slower than GOTO, which makes sense as there should be some overhead to RUN and not just an unconditional jump.

Runs on the Commodore PET

This program runs unmodified on a PET (released in 1977). To run it on the VICE PET emulator (xpet), you should first change to the "shifted" text mode by typing:

 poke 59468,12

CHR_205_Running_on_a_PET.png
665 × 260 pixels

Personal tools