Well, it’s late Sunday afternoon in California, but already after midnight GMT, so I guess I missed the deadline. My code is for the Apple 1, and is 76 bytes of machine language. You need about 176 keystrokes to enter it into WozMon, so it has to be broken into two lines.
80:D8 A9 FF 48 A9 1E 48 A9 FA 85 95 A2 4 A9 FE 85 92 A9 0 18 69 0 18 69 8 85 92 20 AE 0 CA D0 F0 E6 95 E6 95 30
:E4 A9 2 20 AE 0 A9 2 85 C2 A9 8D 20 EF FF A9 26 38 E5 C2 4A A8 A9 A0 20 C5 0 A0 0 A9 AA 20 EF FF 88 10 FA 60
It’s pure self-modifying code, with no tables.
I used a legal pad and a #2 pencil for development, and I assembled and debugged a slightly different version of it using the monitor and mini-assembler on an Apple ][ 'mulator before pasting it into an Apple 1 'mulator and executing.
Thanks for sharing! See also the stardot thread and perhaps the thread on 6502 for people’s various efforts. And of course eventually the competition page will show some of the submissions, I hope.
It will also be interesting to see results for other micros and other languages. (There’s already a PDP-11 program posted on stardot.)
Ok, I decided for a poetic effort in BASIC (for Commodore 8-bit), meaning, rather than optimizing for length (180 bytes including the REMark), I went for a festive underline decoration, nicely filled lines and a poem-like structure.
Mind that the bare algorithm looks something like this (122 bytes), putting into consideration that the argument passed to SPC() is truncated to integer anyway:
Did anyone go for an algorithmic approach?
Mind that the tree consists of lines of 1+2*0*x, 1+2*1*x, 1+2*2*x, 1+2*3*x asterisks, where x = 1,2,3, and the final stem.
Pseudo-code:
for x = [1,2,3]:
for y = [0,1,2,3]:
for s = [0 .. center - y*x]:
print " "
for a = [0 .. 2*y*x]:
print "*"
print "\n"
/* print stem and end */
2 FOR A=1 TO 3:FOR B=1 TO 4:PRINT SPC(20-B*A);STRING$(2*B*A-1,"*"):NEXT:NEXT:PRINT SPC(18)"***"'SPC(18)"***"
Aw, BBC-BASIC and its STRING$ command – this is unfair!
*) Meaning, in Commodore BASIC, we’d either have to define a base string to operate on (compare my “festive underline decoration”) or use FOR-NEXT loops to print the individual characters, which is much lengthier (both in code and runtime).
I absolutely don’t claim this being the shortest dc solution. There possibly is room for improving this one, e.g. by merging the n-spaces and the n-stars macros or finding a total different approach.
Nice! “dc (desk calculator) is a cross-platform reverse-Polish calculator which supports arbitrary-precision arithmetic … one of the oldest Unix utilities, preceding even the invention of the C programming language.”
Well with shell programs, 3 keys and a click comes to mind.
Click on tree, select all, select cut, select paste, select trash can. copied exactly:)
Uinix people can | dev/null
Lots of great ways to print that tree. Good work people. Ben,
Is there any sense in which you could hand-code the CINTCODE, in an analogous way to writing in assembler? Perhaps just tweaking and optimising the compiler’s output?? (Not that this would necessarily be fun, but perhaps it might be…)