See also: part 1, part 2, part 3, part 4, part 5, part 6 and part 7.
Here we go again! Over in the Facebook Color Computer group, David M. shared a link to this year’s Vintage Computing Christmas Challenge from Logiker. Although I did not submit an entry, I did play with last year’s challenge on my TRS-80 Color Computer.
Last year, it was this:
This year, the challenge is a bit more challenging. Per the challenge website, here is sample code for Commodore:
10 print"{clear}" 20 print"" 30 print"" 40 print"" 50 print" * *" 60 print" ** **" 70 print" *** ***" 80 print" **** ****" 90 print" *****************" 100 print" ***************" 110 print" *************" 120 print" ***********" 130 print" *********" 140 print" ***********" 150 print" *************" 160 print" ***************" 170 print" *****************" 180 print" **** ****" 190 print" *** ***" 200 print" ** **" 210 print" * *" 220 goto 220
Starting with that un-optimized version, I will change it to work on the CoCo 1/2/3’s 32-column screen by adjusting it to be properly centered on that display.
10 CLS
50 PRINT" * *"
60 PRINT" ** **"
70 PRINT" *** ***"
80 PRINT" **** ****"
90 PRINT" *****************"
100 PRINT" ***************"
110 PRINT" *************"
120 PRINT" ***********"
130 PRINT" *********"
140 PRINT" ***********"
150 PRINT" *************"
160 PRINT" ***************"
170 PRINT" *****************"
180 PRINT" **** ****"
190 PRINT" *** ***"
200 PRINT" ** **"
210 PRINT" * *"
220 GOTO 220
Unfortunately, this design is 17 rows tall, and the CoCo’s standard display is only 16. It won’t fit:
We should still be able to enter the challenge by having the program print this pattern, even if it scrolls off the screen a bit. To get one extra line there, we can get rid of the line feed at the end of the final PRINT statement in line 210 by adding a semi-colon to the end:
210 PRINT" * *";
And so it begins…
And so it begins
The goal is to make this as small as possible. There were many ways to approach last year’s Christmas tree challenge, and you can read about the results and a follow-up with suggestions folks gave to save a byte or two.
A simple thing is to remove the spaces at the front and replace them with the TAB() command:
10 CLS
50 PRINTTAB(7)" * *"
60 PRINTTAB(7)" ** **"
70 PRINTTAB(7)" *** ***"
80 PRINTTAB(7)" **** ****"
90 PRINTTAB(7)"*****************"
100 PRINTTAB(7)" ***************"
110 PRINTTAB(7)" *************"
120 PRINTTAB(7)" ***********"
130 PRINTTAB(7)" *********"
140 PRINTTAB(7)" ***********"
150 PRINTTAB(7)" *************"
160 PRINTTAB(7)" ***************"
170 PRINTTAB(7)"*****************"
180 PRINTTAB(7)" **** ****"
190 PRINTTAB(7)" *** ***"
200 PRINTTAB(7)" ** **"
210 PRINTTAB(7)" * *";
220 GOTO 220
Although this only looks like it saves a character per line (“TAB(8)” versus “seven spaces”), the code itself will be smaller since the TAB command tokenizes down to one (or maybe two?) bytes.
Also, the ending quote is not needed if it’s the last thing on a line, so they could be removed:
50 PRINTTAB(7)" * *
60 PRINTTAB(7)" ** **
70 PRINTTAB(7)" *** ***
That would save one byte per line.
But, each line number consumes 5-bytes on it’s own, so a better way to save space would be to pack the lines together. Each line you eliminate saves five bytes. That would become pretty unreadable though, but let’s do it anyway:
10 CLS:PRINTTAB(7)" * *":PRINTTAB(7)" ** **":PRINTTAB(7)" *** ***":PRINTTAB(7)" **** ****":PRINTTAB(7)"*****************":PRINTTAB(7)" ***************":PRINTTAB(7)" *************":PRINTTAB(7)" ***********"
130 PRINTTAB(7)" *********":PRINTTAB(7)" ***********":PRINTTAB(7)" *************":PRINTTAB(7)" ***************":PRINTTAB(7)"*****************":PRINTTAB(7)" **** ****":PRINTTAB(7)" *** ***":PRINTTAB(7)" ** **"
210 PRINTTAB(7)" * *";
220 GOTO 220
That’s quite the unreadable mess!
This could still be made better, since the text lines were kept under the input buffer limitation size, but when you enter that line, BASIC compresses it (tokenizes keywords like PRINT, TAB and GOTO) making it take less space. You can then sometimes EDIT the line, Xtend to the end and type a few more characters.
That may or may not be allowed for the Logiker challenge. And since I want to provide code here you could copy and then load in to an emulator, I’ll keep it to the limit of what you could type in.
In the next installment, I’ll see if my brane can figure out a way to generate this code using program logic rather than brute-force PRINT statements.
Until then…