THE CHALLENGE (optimized for minimum size) Author: Juhani Tapaninen @oh8mxl System: C64 Language used (name and possibly version): Basic V2 Length of source code: 93 bytes; from separately written text file using ANSI encoding (File size on disk: 1 block) Length of executable file: 99 bytes; command: PRINT 38911-(FRE(0)-65536*(FRE(0)<0)) Instructions on how to run the code: - install vice c64sc - attach disk image, drive #8: "oh8mxl_c64.d64" - LOAD "OH8MXL",8,1 - RUN Description of how the code works: The code for reference, Packed: 2 FORT=4TO17:S=INT(T/4):W=(T-S*4)*S+S-2ANDS<4:FORP=19-WTO21+W:PRINTTAB(P)"*";:NEXT:PRINT:NEXT Unpacked: 2 FORT=4TO17: S=INT(T/4): W=(T-S*4)*S+S-2ANDS<4: FORP=19-WTO21+W: PRINTTAB(P)"*";: NEXT:PRINT:NEXT T loops the tree from top to bottom. The S equation gives the section number of the tree (1 to 4), W equation gives the half-width of tree (minus one) at current height. The P loop prints the stars centered to screen using efficient VDU command. In more detail: Variables: T=Tree line number from top to bottom, 4 to 17 S=tree Section number 1 to 4 from top to bottom W=half-Width of the tree at current line not including the trunk at the center of the tree -1 P=Position where to print the next star char I started with 2 FOR loops, the first looping through 3 widening sections of the tree and second looping the four lines in each section, and adding the width of the stump separately. The width was calculated from the FOR variables. I was first working on BBC Micro Basic and after several iterations I noticed that the tree half-width not including trunk at highest 11 lines of the tree can be calculated in one FOR loop with equation W=(T MOD 4)*(T DIV 4+1)+T DIV 4 (code has evolved since then, not usable anymore) This equation was further reduced by using the tree section variable S and by changing the MOD and DIV commands to operands that the C64 Basic has. Then, I noticed that I could add even the stump of the tree into the same width calculating equation with the "ANDS<4" logic operation part. For this to work I had to change the W variable not to be "tree half width w/o trunk" but "tree half width w/o trunk -1" since the logic operation returns 0 when we are at the stump. Finally, tweaking the FOR loop to run from 4 to 17 instead of 0 to 13 took 2 bits away from the S equation, yay! (It had a "+1" part in it.) It took many iterations during several evenings to reduce the code to current state. Please note that manually typing the code into C64 requires usage of a few shortcuts like ? for PRINT and fO for FOR and nE for NEXT not to exceed the 2 line limit on one BASIC command line.