3
\$\begingroup\$

Commodore 64 BASIC has abbreviated forms for most of its keywords, ranging from ? being short for PRINT (common across many dialects of BASIC) to C64-specific ones such as D♠ (D followed by SHIFT+A) being short for DATA. When you list a program's source code after typing it in, most of these abbreviations will be expanded (but not all of them -- TI, TI$, and ST won't be) and some optional whitespace will be inserted.

I've been counting the length of C64 programs as "the number of characters typed in", which seems more or less in-line with how other languages are scored. However, Shaun Bebbers has started golfing in C64 BASIC as well, and is counting the length of programs in terms of "bytes of program memory used" (see, for example, this answer).

What's the correct way of counting the length of a program?

\$\endgroup\$

2 Answers 2

6
\$\begingroup\$

Bytes of Memory

Characters, although are an easy measurement, can sometimes produce more than a byte worth of data, (See any character encoding that supports more than 256 unique characters), and sometimes fails to account for tokens. As the program may treat some data as 'tokens', storing it in less bytes then typed, and, To my knowledge, C64-BASIC doesn't support characters larger than a byte, you're simply handicapping yourself by not doing this.

Memory bytes act as a definitive method of counting how many bytes the program takes, and as such, should be the score for code-golf.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Let me make sure I've got this right: you're saying that 1?"HELLO WORLD" and 9999 PRINT"HELLO WORLD" should score the same, at 21 bytes of memory used, despite being 16 and 23 characters long respectively? \$\endgroup\$
    – Mark
    Feb 15, 2017 at 21:24
  • 3
    \$\begingroup\$ Yep, because they encode the same amount of data. \$\endgroup\$
    – ATaco
    Feb 15, 2017 at 21:25
3
\$\begingroup\$

Thanks for the clarity, I was going to ask the same question about Sinclair ZX81 entries - this is the most interesting language to me for code-golf as it's one of the most - if not the most - difficult to minimize and obfuscate.

To get the exact byte count on a Commodore 64, run your program and break into it with RUN/STOP, and then type:

print 38911-(fre(0)-65536*(fre(0)<0)) 

On a VIC-20 or Commodore 128, print fre(0) will work fine. I assume this is the same for the Plus/4 and C16 but I don't know.

To calculate the amount of RAMs used on a ZX81/Timex TS1000/1500, try

PRINT (PEEK 16386+256*PEEK 16387) - (PEEK 16412+256*PEEK 16413)

Note that you can save bytes by making lines longer on the ZX81, so:

10 LET A=VAL "10"

costs less memory (from what I remember) than

10 LET A=10

but the memory-efficient line takes more t-states than the latter. So in order to code-golf properly on the ZX81 I actually need to add in more BASIC keywords in some situations.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .