Christmas Tree

From SizeCoding
Revision as of 13:42, 25 December 2021 by Logiker (talk | contribs) (Initial version of Christmas Tree case study)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

During the Vintage Computing Christmas Challenge 2021 the goad was to create the shape of a given Christmas tree with as few bytes as possible. All platforms and languages were allowed. The tree should be centered and look exactly like shown bellow.

                         *
                        ***
                       *****
                      *******
                        ***
                      *******
                    ***********
                  ***************
                       ***** 
                    *********** 
                 ***************** 
              *********************** 
                        ***
                        ***

There were mainly two kinds of approaches:

  • calculate stars using a formula
  • save amount of stars within data

Do to the trunk of the tree, the second type was more efficient.

Shortest DOS version

The shortest DOS version with 44 bytes came from Hellmood:

org 100h			; define start of code for data access
db 80				; screen width, located at [SI], also "push ax"
mov bx,d			; pointer to data for XLAT
mov cx,1120			; 14 lines with 80 chars each
X: mov ax,cx		; get current sequence position
div byte [si]		; transform to [X,Y] in AL, AH
xlat				; get tree width for current line number
sub ah,40			; center tree in the middle
jnc F				; - 
neg ah				; -
F: sub ah,al		; inside or outside tree?
salc				; set AL depending on carry flag
imul ax,byte -42	; transform into STAR or nothing
int 29h				; write current char to screen
loop X				; repeat unil all chars are plotter
ret					; return to prompt (JMP to former AX=0x0000)
d:db 2,2,12,9,6,3,8,6,4,2,4,3,2,1

Winning entry for C64

The shortest entry overall was for the C64 and was submitted by Serato with only 37 bytes:

		!cpu 6510			; enable unintended opcodes in ACME assembler

		chrout = $FFD2
		crlf = $AAD7
		pntr = $D3
		width = 40

		*=$304-39
table
		!byte width-1  
		!byte width-3  
		!byte width-5  
		!byte width-7  
		!byte width-3  
		!byte width-7  
		!byte width-11 
		!byte width-15 
		!byte width-5  
		!byte width-11 
		!byte width-17 
		!byte width-23 
		!byte width-3  
		!byte width-3  
entry
		lax	table-1,y
		bmi *
		lsr
		sta pntr
		lda #'*'
-		jsr chrout
		inx
		cpx #width
		bne -
		jsr crlf
		iny
		jmp entry
end