Task

Present numbers using the Mayan numbering system   (displaying the Mayan numerals in a cartouche).



Mayan numbers

Normally, Mayan numbers are written vertically   (top─to─bottom)   with the most significant
numeral at the top   (in the sense that decimal numbers are written left─to─right with the most significant
digit at the left).   This task will be using a left─to─right (horizontal) format,   mostly for familiarity and
readability,   and to conserve screen space (when showing the output) on this task page.



Mayan numerals

Mayan numerals   (a base─20 "digit" or glyph)   are written in two orientations,   this
task will be using the "vertical" format   (as displayed below).   Using the vertical format makes
it much easier to draw/construct the Mayan numerals (glyphs) with simple dots (.)
and hyphen (-);     (however, round bullets (•) and long dashes (─)
make a better presentation on Rosetta Code).



Furthermore, each Mayan numeral   (for this task)   is to be displayed as a
cartouche   (enclosed in a box)   to make it easier to parse (read);   the box may be
drawn with any suitable (ASCII or Unicode) characters that are presentable/visible in all web browsers.



Mayan numerals added to Unicode
Mayan numerals (glyphs) were added to the Unicode Standard in June of 2018   (this corresponds with
version 11.0).   But since most web browsers don't support them at this time,   this Rosetta Code
task will be constructing the glyphs with "simple" characters and/or ASCII art.



The "zero" glyph

The Mayan numbering system has the concept of   zero,   and should be shown by a glyph that represents
an upside─down (sea) shell,   or an egg.   The Greek letter theta   (Θ)   can be
used   (which more─or─less, looks like an
egg).   A   commercial at   symbol   (@)   could make a poor substitute.



Mayan glyphs (constructed)

The Mayan numbering system is
a   [vigesimal (base 20)]   positional numeral system.



The Mayan numerals   (and some random numbers)   shown in the   vertical   format would be shown as

      ╔════╗                      ╔════╗                            ╔════╦════╗
      ║    ║                      ║    ║                            ║    ║    ║
      ║    ║                      ║ ∙  ║                            ║    ║    ║
 1──► ║    ║                11──► ║────║                      21──► ║    ║    ║
      ║ ∙  ║                      ║────║                            ║ ∙  ║ ∙  ║
      ╚════╝                      ╚════╝                            ╚════╩════╝
      ╔════╗                      ╔════╗                            ╔════╦════╗
      ║    ║                      ║    ║                            ║    ║    ║
      ║    ║                      ║ ∙∙ ║                            ║    ║    ║
 2──► ║    ║                12──► ║────║                      22──► ║    ║    ║
      ║ ∙∙ ║                      ║────║                            ║ ∙  ║ ∙∙ ║
      ╚════╝                      ╚════╝                            ╚════╩════╝
      ╔════╗                      ╔════╗                            ╔════╦════╗
      ║    ║                      ║    ║                            ║    ║    ║
      ║    ║                      ║∙∙∙ ║                            ║    ║    ║
 3──► ║    ║                13──► ║────║                      40──► ║    ║    ║
      ║∙∙∙ ║                      ║────║                            ║ ∙∙ ║ Θ  ║
      ╚════╝                      ╚════╝                            ╚════╩════╝
      ╔════╗                      ╔════╗                            ╔════╦════╗
      ║    ║                      ║    ║                            ║    ║    ║
      ║    ║                      ║∙∙∙∙║                            ║    ║    ║
 4──► ║    ║                14──► ║────║                      80──► ║    ║    ║
      ║∙∙∙∙║                      ║────║                            ║∙∙∙∙║ Θ  ║
      ╚════╝                      ╚════╝                            ╚════╩════╝
      ╔════╗                      ╔════╗                            ╔════╦════╗
      ║    ║                      ║    ║                            ║    ║    ║
      ║    ║                      ║────║                            ║    ║    ║
 5──► ║    ║                15──► ║────║                      90──► ║    ║────║
      ║────║                      ║────║                            ║∙∙∙∙║────║
      ╚════╝                      ╚════╝                            ╚════╩════╝
      ╔════╗                      ╔════╗                            ╔════╦════╗
      ║    ║                      ║ ∙  ║                            ║    ║    ║
      ║    ║                      ║────║                            ║    ║    ║
 6──► ║ ∙  ║                16──► ║────║                     100──► ║    ║    ║
      ║────║                      ║────║                            ║────║ Θ  ║
      ╚════╝                      ╚════╝                            ╚════╩════╝
      ╔════╗                      ╔════╗                            ╔════╦════╗
      ║    ║                      ║ ∙∙ ║                            ║    ║    ║
      ║    ║                      ║────║                            ║    ║    ║
 7──► ║ ∙∙ ║                17──► ║────║                     200──► ║────║    ║
      ║────║                      ║────║                            ║────║ Θ  ║
      ╚════╝                      ╚════╝                            ╚════╩════╝
      ╔════╗                      ╔════╗                            ╔════╦════╗
      ║    ║                      ║∙∙∙ ║                            ║    ║    ║
      ║    ║                      ║────║                     300──► ║────║    ║
 8──► ║∙∙∙ ║                18──► ║────║                            ║────║    ║
      ║────║                      ║────║                            ║────║ Θ  ║
      ╚════╝                      ╚════╝                            ╚════╩════╝
      ╔════╗                      ╔════╗                            ╔════╦════╦════╗
      ║    ║                      ║∙∙∙∙║                            ║    ║    ║    ║
      ║    ║                      ║────║                     400──► ║    ║    ║    ║
 9──► ║∙∙∙∙║                19──► ║────║                            ║    ║    ║    ║
      ║────║                      ║────║                            ║ ∙  ║ Θ  ║ Θ  ║
      ╚════╝                      ╚════╝                            ╚════╩════╩════╝
      ╔════╗                      ╔════╦════╗                       ╔════╦════╦════╦════╗
      ║    ║                      ║    ║    ║                       ║    ║    ║    ║    ║
      ║    ║                      ║    ║    ║                       ║    ║    ║    ║    ║
10──► ║────║                20──► ║    ║    ║             16,000──► ║    ║    ║    ║    ║
      ║────║                      ║ ∙  ║ Θ  ║                       ║ ∙∙ ║ Θ  ║ Θ  ║ Θ  ║
      ╚════╝                      ╚════╩════╝                       ╚════╩════╩════╩════╝



Note that the Mayan numeral   13   in   horizontal   format would be shown as:

                                  ╔════╗
                                  ║  ││║
                                  ║ ∙││║
                            13──► ║ ∙││║        ◄─── this glyph form won't be used in this Rosetta Code task.
                                  ║ ∙││║
                                  ╚════╝



Other forms of cartouches (boxes) can be used for this task.



Task requirements

   convert the following decimal numbers to Mayan numbers:
       4,005
       8,017
   326,205
   886,205
   show a   unique   interesting/pretty/unusual/intriguing/odd/amusing/weird   Mayan number
   show all output here


Related tasks

   Roman numerals/Encode   ─── convert numeric values into Roman numerals
   Roman numerals/Decode   ─── convert Roman numerals into Arabic numbers


See also

   The Wikipedia entry:   [Mayan numerals]


putch:	equ	2
puts:	equ	9
	org	100h
	lxi	h,80h	; Get length of command line input
	mov	a,m
	cpi	2
	rc		; If no input, stop
	add	l
	mov	l,a	; Go to end of numbers
	mov	c,l	; C = end of numbers
	inx	h
	mvi	m,0FFh	; Terminate digit sequence with FFh
	dcx	h
sub0:	mov	a,m
	cpi	32	; When space reached, we're at the beginning
	jz	to20
	sui	'0'	; Subtract '0' from each digit and make sure
	rc		; they are all valid
	cpi	10	
	rnc	 
	mov	m,a
	dcx 	h
	jmp	sub0
to20:	mov	a,c	; Calculate amount of numbers
	sui	81h
	mov	c,a
to20l:	mov	e,c	; E = digit counter
	mvi	l,82h	; Start at beginning
div2:	mov	a,m	; Grab digit
	jnc	$+5	; If carry, add ten
	adi	10
	rar		; Divide by two
	mov	m,a	; Write back
	inx	h
	dcr	e
	jnz	div2	; Keep going
	dcx	h	; For the last number we want
	ral		; to keep the carry
	mov	m,a	; This digit is now base-20
	dcr	c	; One fewer digit left to do
	jnz	to20l
	mvi	l,81h	; Find start and end of numbers
start:	inx	h
	mov	a,m
	ana	a
	jz	start
	mov	b,l	; B = start
	inr	a	; If number is zero, output nothing
	rz 
nend:	inx	h
	mov	a,m
	inr	a
	jnz	nend
	mov	a,l	; A = end
	sub	b
	mov	c,a	; C = amount
	call	edge
	mvi	d,3	; D=line
line:	push	b	; Save start and amount
	mov	l,b	; HL = first digit
	mvi	h,0
num:	call	dline	; Print line for digit
	inx	h	; Next digit
	dcr	c
	jnz	num
	push	d	; Save line number
	lxi	d,dn	; Print end of line
	call	print
	pop 	d	; Restore variables
	pop 	b
	dcr	d
	jp	line	; Print next line
edge:	push	b	; Print edge (top or bottom)
edge_l:	push	b	; Keep counter
	lxi	d,edges	
	call 	print
	pop	b
	dcr 	c
	jnz	edge_l
	lxi	d,edgen	
	call	print
	pop	b
	ret	
dline:	push	h	; Print line for digit (D'th from bottom)
	push	d
	push	b
	mov	a,m
	ora	d	; Line and number both 0?
	jnz	$+9
	lxi	d,dz	; Then print line with @
	jmp	dnum
	mov	a,d	; 5 * line
	add	a
	add	a
	add	d
	mov	e,a
	mov	a,m	; A -= 5 * line
	sub	e
	lxi	d,d0	; If <0, empty
	jm	dnum
	cpi	5
	jc	$+9
	lxi	d,d5	; If >=5, ----
	jmp	dnum
	add	a	; Otherwise, d[n]
	mov	l,a
	add	a
	add	l
	mov	l,a
	mvi	h,0
	dad	d
	xchg
dnum:	call	print
	pop	b
	pop	d
	pop	h
	ret		
print:	mvi	c,puts
	jmp	5
edges:	db	'+----$'
edgen:	db	'+',13,10,'$'
dz:	db	'| @  $'
d0:	db	'|    $| .  $| .. $|... $|....$'
d5:	db	'|----$'
dn:	db	'|',13,10,'$'